Skip to content

Instantly share code, notes, and snippets.

@ironsmile
Created May 29, 2011 15:14
Show Gist options
  • Save ironsmile/997849 to your computer and use it in GitHub Desktop.
Save ironsmile/997849 to your computer and use it in GitHub Desktop.
ctimer for blago
#include <iostream>
#include <sys/time.h>
int main (int argc, char * const argv[]) {
timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
int * arr = new int[100000000];
for (int i = 0; i < 100000000; ++i) {
*(arr+i) = i;
}
for (int i = 0; i < 100000000; ++i){
;
}
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0);
std::cout<<mtime;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment