Created
July 5, 2017 18:39
-
-
Save jarun/42c31f718b6299c4a4996cf11d490c0c to your computer and use it in GitHub Desktop.
microsec timer in C for profiling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <sys/time.h> | |
int main() | |
{ | |
struct timeval t1, t2; | |
double elapsedTime; | |
// start timer | |
gettimeofday(&t1, NULL); | |
// do something | |
// ... | |
// stop timer | |
gettimeofday(&t2, NULL); | |
// compute and print the elapsed time in millisec | |
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0; // sec to ms | |
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0; // us to ms | |
printf("%lf\n", elapsedTime); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment