Created
July 5, 2018 06:41
-
-
Save gitsrc/75503d18998ed27da15dbde5982d6db9 to your computer and use it in GitHub Desktop.
C获取程序运行时间
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> | |
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