Menu

processor run time

xlonehats
2007-09-04
2012-09-26
  • xlonehats

    xlonehats - 2007-09-04

    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

     
    • Wayne Keen

      Wayne Keen - 2007-09-04

      This topic has been discussed here before - a forum search should bring it up for you.

      Wayne

       
    • Anonymous

      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

       
    • xlonehats

      xlonehats - 2007-09-05

      thnks mate...nice suggestion..

       
      • Anonymous

        Anonymous - 2007-09-05

        Which one!? ;)

         

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.