Time my application/function

Match word(s).

If you have any questions or comments,
please visit us on the Forums.

FAQ > How do I... (Level 2) > Time my application/function

This item was added on: 2003/03/22

The best way to time the performance of a program is to use a profiler, it is the most accurate and gives more useful output than a simple minded timing. But if you don't have access to a profiler, you can get some of its functionality by way of the time functions in <time.h> or <ctime>:

#include <stdio.h> 
#include <time.h> 

int main ( void )
  clock_t start, end;

  /* Start the timer */
  start = clock();

  printf ( "Please wait a few moments and hit return\n" );

  /* End the timer */
  end = clock();

  /* Print out the difference */
  printf ( "The interval was: %f seconds\n",
    (double)( end - start ) / (double)CLOCKS_PER_SEC );

  return 0;

Credit: Prelude

Script provided by SmartCGIs