Posted By

mrAlexGray on 04/10/11


Tagged

Development benchmark


Versions (?)

How to measure time of execution


 / Published in: C
 

  1. struct timeval start, end, delta;
  2. assert(gettimeofday(&start, NULL) != -1);
  3.  
  4. // LAPS should be huge (about a million, probably)
  5. for (int i = 0; i < LAPS; i++)
  6. test_function();
  7.  
  8. assert(gettimeofday(&end, NULL) != -1);
  9. timersub(&end, &start, &delta);
  10. uint64_t delta_ns = (delta.tv_sec * NSEC_PER_SEC + delta.tv_usec * NSEC_PER_USEC) / LAPS;

Report this snippet  

You need to login to post a comment.