Skip to content

Instantly share code, notes, and snippets.

@dadeba
Created February 1, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dadeba/1716046 to your computer and use it in GitHub Desktop.
Save dadeba/1716046 to your computer and use it in GitHub Desktop.
measure the elapsed time on linux
#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