Instantly share code, notes, and snippets.

Embed
What would you like to do?
Timing loop direction and speed
#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