Skip to content

Instantly share code, notes, and snippets.

@samueljackson92
Created March 21, 2013 17:53
Show Gist options
  • Save samueljackson92/5215116 to your computer and use it in GitHub Desktop.
Save samueljackson92/5215116 to your computer and use it in GitHub Desktop.
C/C++ code for calculating delta time. Output in seconds.
timeval t1, t2;
double elapsedTime;
//start timer
gettimeofday(&t1, NULL);
//do stuff...
//stop timer
gettimeofday(&t2, NULL);
//compute
elapsedTime = (t2.tv_sec - t1.tv_sec) * 1000.0;
elapsedTime += (t2.tv_usec - t1.tv_usec) / 1000.0;
//convert to seconds
delta = elapsedTime /1000;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment