Created
February 1, 2012 09:01
-
-
Save dadeba/1716046 to your computer and use it in GitHub Desktop.
measure the elapsed time on linux
This file contains 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 <time.h> | |
#include <sys/time.h> | |
#include <sys/resource.h> | |
// How to use? | |
// | |
// double st = e_time(); | |
// ... where computation going on ... | |
// double en = e_time(); | |
// | |
// the elapsed time is en - st in seconds | |
double e_time(void) | |
{ | |
static struct timeval now; | |
gettimeofday(&now, NULL); | |
return (double)(now.tv_sec + now.tv_usec/1000000.0); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment