linux - sleep(0)? consistent time keeping in code? -


Now I am loading a file then using gettimeofday and tracking CPU time with tv_usec

My results change, I get 250 to 280s but sometimes 300 or 500 I wrote with sleep and sleep (0) and (1) success, the time is still very different I thought Sleep (1) (second in linux, windows not sleeping MS) will solve it. How can I keep track of time in a more consistent way for testing? Should I wait too much test data and more complex code before measuring?

Currently the recommended interface for high-ray time on Linux (and posx in general) is clock_jetite View the man page

 

  clock_gettime (CLOCK_REALTIME, struct timespec * tp) // wall clock clock clock_gettime (CLOCK_PROCESS_CPUTIME_ID, struct timespec * tp) / / For CPU time> but read the man page Note that you need to link to -lrt, because POSIX says so, I think. Maybe to avoid the conflicts of symbols in LC, for old programs that define their own clock_gettime? But dynamic lobbies use weak symbols ... 

The best sleeping job is nanosleep. It does not mess around with any nonsense like signs or sleep, it's just defined for sleeping, and there is no other side effect. And it tells you that if you get up early (like signals), then you do not have to call any other time function.

Still, you have a hard time for a representative, such a small thing in which a system call involves a large amount of opportunities for diversity, such as schedulers can decide that some other work (It's unlikely that if your process started right now, you will not use your timeals yet). CPU cache (L2 and TLB) can be easily possible.

If you have a multi-core machine and single-threaded benchmark for customizable code, you can pin it to the realtime preference at any time. Your core should be sure that you choose the core that the interrupts Does not keep, or your keyboard (and everything else) will stop until it is complete. Use this Taskset (to pin a CPU) and RRTR (to set up Realtime Preo) This mail was sent to gmp-devel with this move:

Oh, the most For precise time, you can use yourself at rdtsc (x86 / amd64). If you do not have any other options in the bunching, then this is not a bad idea. Take a benchmarking framework to implement your function in GMP which is a very good one. This is probably not well established for benchmarking tasks which are not in GMP and say MPN_Hailly, although I do not remember, and it's worth a is.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -