Skip to content

Instantly share code, notes, and snippets.

@hvasconcelos
Created November 19, 2013 12:27
Show Gist options
  • Save hvasconcelos/7544617 to your computer and use it in GitHub Desktop.
Save hvasconcelos/7544617 to your computer and use it in GitHub Desktop.
Time spent doing something
#include <sys/time.h>
#include <stdio.h>
#include <string.h>
long timevaldiff(struct timeval *starttime, struct timeval *finishtime) {
long msec;
msec=(finishtime->tv_sec-starttime->tv_sec)*1000;
msec+=(finishtime->tv_usec-starttime->tv_usec)/1000;
return msec;
}
int main () {
struct timeval start, finish;
long msec;
while(1){
gettimeofday(&start, NULL);
// do Something
gettimeofday(&finish, NULL);
msec = timevaldiff(&start, &finish);
printf("Elapsed time for: %d milliseconds.\n", msec);
sleep(1);
}
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment