Need help to time algorithms in C (msec/usec accuracy)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jisrar
    New Member
    • Feb 2008
    • 1

    Need help to time algorithms in C (msec/usec accuracy)

    Hi,

    I have written two algorithms and need to be compare them in terms of how long each take. I have tried clock() before/after each algorithm but my CLOCKS_PER_SEC variable is defined as 1000 which only gives me accuracy upto 1 msec. I have alo tried time() but this is accurate upto 1 sec. I have tried _ftime() and accessed the msec part but again I am not sure if this is accurate. In some cases I am getting same sec/msec values before and after my algorithm.

    What is the best way of determining execution time which is at least semi-reliable and is accurate utp usec level.

    Thanks in advance for your help.

    Regards,

    Junaid.
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    You could run the program 100,000 times and divide your elapsed time by 100,000, for example.

    Comment

    Working...