Skip to content

Instantly share code, notes, and snippets.

@gitsrc
Created July 5, 2018 06:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gitsrc/75503d18998ed27da15dbde5982d6db9 to your computer and use it in GitHub Desktop.
Save gitsrc/75503d18998ed27da15dbde5982d6db9 to your computer and use it in GitHub Desktop.
C获取程序运行时间
#include <sys/time.h>
#include <stdio.h>
float timedifference_msec(struct timeval t0, struct timeval t1)
{
return (t1.tv_sec - t0.tv_sec) * 1000.0f + (t1.tv_usec - t0.tv_usec) / 1000.0f;
}
int main(void)
{
struct timeval t0;
struct timeval t1;
float elapsed;
gettimeofday(&t0, 0);
/* ... YOUR CODE HERE ... */
gettimeofday(&t1, 0);
elapsed = timedifference_msec(t0, t1);
printf("Code executed in %f milliseconds.\n", elapsed);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment