Created
March 16, 2018 06:22
-
-
Save annidy/5ab4d5a261a5582b27dfe84b9ffefdf9 to your computer and use it in GitHub Desktop.
快速计算fps
This file contains hidden or 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
static int counter; | |
static long counter_ms; | |
struct timeval time; | |
long now; | |
if (counter == 0) { | |
counter = 1; | |
gettimeofday(&time, NULL); | |
counter_ms = (time.tv_sec * 1000) + (time.tv_usec / 1000); | |
} else if (counter > 100) { | |
gettimeofday(&time, NULL); | |
now = (time.tv_sec * 1000) + (time.tv_usec / 1000); | |
printf("fps = %ld\n", counter * 1000 / (now - counter_ms)); | |
counter = 0; | |
} else { | |
counter++; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment