One of our comrades, Peter Mortensen , asked a question about Super User about an application that can consume an arbitrary percentage of the processor time. This aroused my interest.
My question is: how could such an application be made:
Here are some of my general ideas and why I think they are bad:
- A calculation program may be executed that will use algorithms that are ineffective in terms of purpose. The problem with this option is that the application will basically have one gear. To solve this, we will need several algorithms of various inefficiencies in order to provide more than one transmission. However, the user will not be able to choose to use 50%. He will need to choose one of the algorithms and see how it works on his computer.
- An application can be created using a workflow that will be set to sleep from time to time. In this way, the user can control how long the thread falls asleep between each execution and monitors CPU usage. However, although average usage will be controlled, at one point the thread will either sleep or consume resources, so this is not a good solution.
- This will be the number one option. An application can be made in such a way as to use cache skips or speculative compilation in Java. For example, a loop can be executed that will control the calculation and cause it to skip the cache in the user interval. This will slow down the calculations, but it will be difficult to implement. Or in Java JIT optimizations can be used. The conditional loop will execute in such a way that the JIT optimizes the condition. After the condition is removed, the JIT will have to de-optimize the code and execute it. But if it stores both optimized and non-optimized versions of the code, it will work only once. In addition, something like this will require a lot of knowledge on optimizing Java for it to work.
Any other ideas on how to make the program intentionally slow?
- C, ++, # Java, , # Java .