Skip to content

Instantly share code, notes, and snippets.

@yongzhy
Created February 27, 2014 02:28
Show Gist options
  • Save yongzhy/9243130 to your computer and use it in GitHub Desktop.
Save yongzhy/9243130 to your computer and use it in GitHub Desktop.
Utility function for benchmark in C code
#ifdef WIN32
#include <windows.h>
double get_time()
{
LARGE_INTEGER t, f;
QueryPerformanceCounter(&t);
QueryPerformanceFrequency(&f);
return (double)t.QuadPart/(double)f.QuadPart;
}
#else
#include <sys/time.h>
#include <sys/resource.h>
double get_time()
{
struct timeval t;
struct timezone tzp;
gettimeofday(&t, &tzp);
return t.tv_sec + t.tv_usec*1e-6;
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment