Created
November 19, 2013 12:27
-
-
Save hvasconcelos/7544617 to your computer and use it in GitHub Desktop.
Time spent doing something
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 <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