hi all....can anyone help me figure out how to calculate run times using dev c++
im writing a program which analyses some sorting algorithms in terms of efficiency...
i have to compare each algorithm with the same data set...
i have used clock() methods from time.h library but it gives no. of seconds elapsed
can i hav a more efficient way of getting time...eg in nanoseconds
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
This topic has been discussed here before - a forum search should bring it up for you.
Wayne
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Anonymous
-
2007-09-04
clock() does not return seconds it returns clock ticks. The number of clock ticks per second is platform specific and is defined by CLOCKS_PER_SEC. In Win32 CLOCKS_PER_SEC is 1000, so clock returns elapsed time in milliseconds. That said it actually only increments every 10ms (by 10 of course).
If your algorithms execute so quickly that ten millisecond resolution is insufficient, you can merely execute the code multiple times in a loop to determine higher accuracy - so for example if it takes 100ms to execute 1000 times, it takes 100us to execute. On the other hand if they execute that fast one might suggest that perhaps you should use a larger data set to sort. By trying to get nanosecond accuracy, you are probably sweating the small stuff - at that resolution just moving the mouse pointer is likely to affect the results; and you have no control over what the OS or background processes might choose to do that would affect the results in the millisecond range of magnitude.
If you really feel the need for high resolution timing you can use QueryPerformanceCounter() ( http://support.microsoft.com/kb/172338 ). With that you will get sub-microsecond timing. For nanosecond timing, you'll have to use the same multiple execution trick I suggested above.
Clifford
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hi all....can anyone help me figure out how to calculate run times using dev c++
im writing a program which analyses some sorting algorithms in terms of efficiency...
i have to compare each algorithm with the same data set...
i have used clock() methods from time.h library but it gives no. of seconds elapsed
can i hav a more efficient way of getting time...eg in nanoseconds
This topic has been discussed here before - a forum search should bring it up for you.
Wayne
clock() does not return seconds it returns clock ticks. The number of clock ticks per second is platform specific and is defined by CLOCKS_PER_SEC. In Win32 CLOCKS_PER_SEC is 1000, so clock returns elapsed time in milliseconds. That said it actually only increments every 10ms (by 10 of course).
If your algorithms execute so quickly that ten millisecond resolution is insufficient, you can merely execute the code multiple times in a loop to determine higher accuracy - so for example if it takes 100ms to execute 1000 times, it takes 100us to execute. On the other hand if they execute that fast one might suggest that perhaps you should use a larger data set to sort. By trying to get nanosecond accuracy, you are probably sweating the small stuff - at that resolution just moving the mouse pointer is likely to affect the results; and you have no control over what the OS or background processes might choose to do that would affect the results in the millisecond range of magnitude.
If you really feel the need for high resolution timing you can use QueryPerformanceCounter() ( http://support.microsoft.com/kb/172338 ). With that you will get sub-microsecond timing. For nanosecond timing, you'll have to use the same multiple execution trick I suggested above.
Clifford
thnks mate...nice suggestion..
Which one!? ;)