Skip to content

Instantly share code, notes, and snippets.

@cedmundo
Created September 18, 2014 13:40
Show Gist options
  • Save cedmundo/4cfaf2ee150c43bbfbe6 to your computer and use it in GitHub Desktop.
Save cedmundo/4cfaf2ee150c43bbfbe6 to your computer and use it in GitHub Desktop.
#include <sys/time.h>
#include <stdio.h>
#include <unistd.h>
int main()
{
struct timeval start, end;
long mtime, seconds, useconds;
gettimeofday(&start, NULL);
usleep(2000);
gettimeofday(&end, NULL);
seconds = end.tv_sec - start.tv_sec;
useconds = end.tv_usec - start.tv_usec;
mtime = ((seconds) * 1000 + useconds/1000.0) + 0.5;
printf("Elapsed time: %ld milliseconds\n", mtime);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment