So I know that clock() measures clock cycles, and thus isn't very good for measuring time, and I know there are functions like omp_get_wtime() for getting the wall time, but it is frustrating for me that the wall time varies so much, and was wondering if there was some way to measure distinct clock cycles (only one cycle even if more than one thread executed in it). It has to be something relatively simple/native. Thanks
+1
A:
Are you sure that taking time measurements will not work for you? Keep in mind you can only measure to so many milliseconds, depending upon the OS.
Justin Ethier
2010-03-18 02:16:53
A:
See FreeMemory's answer to this question for RDTSC if your using x86 which I've tested and seems to work fine on my system (mac), but see my answer to this question. Also see the criticism of RDTSC here.
It's not usually worth it to get down to too low a level of detail though, other bits and pieces of work the computer needs to do will use up clock cycles, so it will vary depending on load. I find omp_get_wtime()
sufficient, though I need to put my code in an extra loop to make sure it takes about a second to ensure consistent results from run to run.
Ramashalanka
2010-03-18 02:52:08