Created
February 27, 2014 02:28
-
-
Save yongzhy/9243130 to your computer and use it in GitHub Desktop.
Utility function for benchmark in C code
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
#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