Created
March 23, 2016 21:22
-
-
Save phantomfive/27fc033c8233cc57ffe8 to your computer and use it in GitHub Desktop.
Timing loop direction and speed
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 <stdio.h> | |
#include <sys/resource.h> | |
int getTime() { | |
struct rusage r; | |
if(getrusage(RUSAGE_SELF, &r)!=0) {perror("FAIL RUSAGE");} | |
double u = (r.ru_utime.tv_sec * 1000) + (r.ru_utime.tv_usec/1000.0); | |
double s = (r.ru_stime.tv_sec * 1000) + (r.ru_stime.tv_usec/1000.0); | |
printf("-----------> u %lf, s %lf\n", u, s); | |
return u + s; | |
} | |
int main(){ | |
int j=0; | |
int i=0; | |
int k=0; | |
double t1 = getTime(); | |
for(k=0; k<10;k++) { | |
for(i=1000000000;i>=0;i--) { | |
j = i; | |
} | |
} | |
double t2 = getTime(); | |
printf ("t1 %lf, t2 %lf, diff %lf\n", t1, t2, t2-t1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment