How to measure time of execution


/ Published in: C
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.