Search code examples
c++profilingbenchmarkinggprof

Simple operation to waste time?


I'm looking for a simple operation / routine which can "waste" time if repeated continuously.

I'm researching how gprof profiles applications, so this "time waster" needs to waste time in the user space and should not require external libraries. IE, calling sleep(20) will "waste" 20 seconds of time, but gprof will not record this time because it occurred within another library.

Any recommendations for simple tasks which can be repeated to waste time?


Solution

  • Another variant on Tomalak's solution is to set up an alarm, and so in your busy-wait loop, you don't need to keep issuing a system call, but instead just check if the signal has been sent.