testsprite2: report average FPS in blocks of five seconds. SDL-ryan-batching-renderer
authorRyan C. Gordon <icculus@icculus.org>
Thu, 20 Sep 2018 15:41:57 -0400
branchSDL-ryan-batching-renderer
changeset 122109f9dbcce30b3
parent 12209 042096b6e332
child 12211 0d8f33ad5fbb
testsprite2: report average FPS in blocks of five seconds.

This makes the reporting more accurate, vs startup inefficiencies and other
scheduling burps.
test/testsprite2.c
     1.1 --- a/test/testsprite2.c	Sun Sep 09 15:09:38 2018 -0400
     1.2 +++ b/test/testsprite2.c	Thu Sep 20 15:41:57 2018 -0400
     1.3 @@ -37,6 +37,8 @@
     1.4  static SDL_Rect *velocities;
     1.5  static int sprite_w, sprite_h;
     1.6  static SDL_BlendMode blendMode = SDL_BLENDMODE_BLEND;
     1.7 +static Uint32 next_fps_check, frames;
     1.8 +static const Uint32 fps_check_delay = 5000;
     1.9  
    1.10  /* Number of iterations to move sprites - used for visual tests. */
    1.11  /* -1: infinite random moves (default); >=0: enables N deterministic moves */
    1.12 @@ -244,6 +246,7 @@
    1.13  void
    1.14  loop()
    1.15  {
    1.16 +    Uint32 now;
    1.17      int i;
    1.18      SDL_Event event;
    1.19  
    1.20 @@ -261,13 +264,24 @@
    1.21          emscripten_cancel_main_loop();
    1.22      }
    1.23  #endif
    1.24 +
    1.25 +    frames++;
    1.26 +    now = SDL_GetTicks();
    1.27 +    if (SDL_TICKS_PASSED(now, next_fps_check)) {
    1.28 +        /* Print out some timing information */
    1.29 +        const Uint32 then = next_fps_check - fps_check_delay;
    1.30 +        const double fps = ((double) frames * 1000) / (now - then);
    1.31 +        SDL_Log("%2.2f frames per second\n", fps);
    1.32 +        next_fps_check = now + fps_check_delay;
    1.33 +        frames = 0;
    1.34 +    }
    1.35 +
    1.36  }
    1.37  
    1.38  int
    1.39  main(int argc, char *argv[])
    1.40  {
    1.41      int i;
    1.42 -    Uint32 then, now, frames;
    1.43      Uint64 seed;
    1.44      const char *icon = "icon.bmp";
    1.45  
    1.46 @@ -384,24 +398,17 @@
    1.47  
    1.48      /* Main render loop */
    1.49      frames = 0;
    1.50 -    then = SDL_GetTicks();
    1.51 +    next_fps_check = SDL_GetTicks() + fps_check_delay;
    1.52      done = 0;
    1.53  
    1.54  #ifdef __EMSCRIPTEN__
    1.55      emscripten_set_main_loop(loop, 0, 1);
    1.56  #else
    1.57      while (!done) {
    1.58 -        ++frames;
    1.59          loop();
    1.60      }
    1.61  #endif
    1.62  
    1.63 -    /* Print out some timing information */
    1.64 -    now = SDL_GetTicks();
    1.65 -    if (now > then) {
    1.66 -        double fps = ((double) frames * 1000) / (now - then);
    1.67 -        SDL_Log("%2.2f frames per second\n", fps);
    1.68 -    }
    1.69      quit(0);
    1.70      return 0;
    1.71  }