I am analyzing a parallel algorithm running on multiple processors.
But it is a simple one, so I need to simulate a long running operation to analyze effective speedup.
-
sleep()/usleep() is not an option. I need to keep CPU busy, so that slave program can’t work during times when other slaves sleep. Here speedup is incorrect.
-
Long empty for-loop is an option. But I also want to set the operation time explicitly.
Is there a way to combine these two or use something else to get time-fixed long operation?
Call
gettimeofdaybefore entering the loop and remember the time. Within the loop, callgettimeofdaycontinuously and calculate the difference between the current time and the beginning. When the difference is big enough, break out of the loop.In essence, something like that: