![]() If the system time(1) is not enough, you might make your own measurement facility see also getrusage(2) I'm skeptical about you getting more accurate measures.īTW on my i3770K recent GNU/Linux (4.2 kernel, Debian/Sid/x86-64) desktop computer, "system"-calls like time(2) or clock_gettime(2) runs in about 3 or 4 nanoseconds (thanks to vdso(7) which avoid the burden of a real syscall.) so you could use them inside your program quite often. ![]() That take the mean (or the worst, or the best, depending what you are after) of the measures. To get significant measures, you should change the benchmarked application to run in more than a few seconds (perhaps adding some loop in main, or run with a bigger data set.), and repeat the benchmarked command a dozen times. You should benchmark your command several times. ) so it does not make any sense to measure the execution of some command with more than one millisecond -or perhaps 100µs if you are lucky- of precision. Pointy at 15:35 You might try to use setTimeout instead of setInterval using various callbacks. You can use setTimeout () instead of setInterval (), keeping track of the time drift and adjusting each sleep period accordingly. And the OS also adds randomness ( scheduling, context switches, interrupts, page cache, copy-on-write, demand-paging. at 15:34 Youre at the mercy of the browser (and the host operating system). If you want to measure timing for particular functions, learn how to profile your application ( gprof, oprofile etc etc.)īe aware that on current (laptop, desktop, server) out-of-order pipelined superscalar processors with complex CPU caches and TLB and branch predictors, the execution time of some tiny loop or sequence of machine instruction is not reproducible (the nanosecond count will vary from one run to the next). 8) times, and take the average (perhaps dropping the best & worst timing). If you want to measure the performance of a whole program, make it run for at least several seconds, and measure the time several (e.g. There is also the RDTSC machine instruction.Īnd don't forget that the timing of execution, is from an application point of view, non deterministic and non reproductible (think about context switches, cache misses, interrupts, etc. ![]() If you have the source code of the application to measure, you might use the clock or clock_gettime functions, but don't hope for better than a dozen of microseconds of accuracy. So any additional digit you've got is meaningless (and essentially random). It does not have much sense to want microsecond accuracy for such measures. I do agree with Employed Russian's answer. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |