For the purpose of testing my app (that detects the current CPU usage) I need to set an artificial work load on the CPUs, for example: 10%, 20%, 30%, etc. up to a 100%. Is there any way to do this?
Use any cpu-bound code you want, then wax-on, wax-off.
In other words,
to achieve 50% load, run the cpu-bound code for x ms, then do nothing for x ms.
to achieve other loads, well, you do the math.
doing nothing is easy, sleep, pause, delay, etc. if c++ 11, try threads and
std::this_thread::sleep_for (std::chrono::milliseconds(100));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With