Skip to content

Instantly share code, notes, and snippets.

@annidy
Created March 16, 2018 06:22
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 annidy/5ab4d5a261a5582b27dfe84b9ffefdf9 to your computer and use it in GitHub Desktop.
Save annidy/5ab4d5a261a5582b27dfe84b9ffefdf9 to your computer and use it in GitHub Desktop.
快速计算fps
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