Skip to content

Instantly share code, notes, and snippets.

@annidy annidy/fps.c
Created Mar 16, 2018

Embed
What would you like to do?
快速计算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
You can’t perform that action at this time.