I coded a very simple tetris clone to get started, and wanted to see how bad the frames per second would be for my implementation. After setting up some code to dump a FPS measurement to logcat over a USB cable, I noticed that the FPS i was getting was way lower than what SpriteMethodTest was getting for roughly the same complexity. I was getting roughly ~18-22 FPS, while the SpriteMethodTest was reporting ~40-50. My app was rendering ~100 32x32 sprites using glDrawTexfOES, so i was expecting roughly similar result. When my app is paused, the physics update loop is short circuited, so I know I am not spending eons doing other calcs. Pausing doesn't seem to alter the FPS by any noticeable margin. I also set all of my textures to the same one, to make sure the texture binding wasn't slowing me down, with no impact on FPS. I also forced the device to NOT run in compatibility mode, as it was doing a zoom-to-fit type of operation before. No change in FPS.
This is on a Droid Incredible btw. I know this is fill rate limited, but this seems pretty silly.
After some investigating, I realized that the numbers produced by SpriteMethodTest were purely based on the time spent during onDraw + the page flip, and not a true measure of FPS. So I added the same code I was using to measure FPS in my app to SpriteMethodTest. It got roughly the same results as my app. I add more sprites, and SpritMethodTest reports lower fps, but the logcat listed fps doesn't change much if at all.
The funny thing is that the screen drawing looks faster than 20 fps, so now I am doubting the code i used (or my eyes). I essentially stole the code used in SpriteText, and converted it to use Log() instead of writing sprites on the screen. I execute this at the end of each drawFrame().
Using java Syntax Highlighting
- private final static float SAMPLE_FACTOR = 1.0f / SAMPLE_PERIOD_FRAMES;
- private void drawMsPF(GL10 gl, float rightMargin) {
- long time = SystemClock.uptimeMillis();
- if (mStartTime == 0) {
- mStartTime = time;
- }
- if (mFrames++ == SAMPLE_PERIOD_FRAMES) {
- mFrames = 0;
- long delta = time - mStartTime;
- mStartTime = time;
- mMsPerFrame = (delta * SAMPLE_FACTOR);
- if (mMsPerFrame > 0) {
- Log.v(TAG, "fps = " + mMsPerFrame);
- }
- }
- }
Parsed in 0.011 seconds, using GeSHi 1.0.8.4
I don't see anything obviously wrong with this code. I played around with SAMPLE_PERIOD_FRAMES a good bit, but the results seemed fairly stable.
1. How are other people measuring FPS?
2. Is there anything wrong the code above for measuring the true number of frames per second?
3. Any ideas as to why SpriteMethodTest reports numbers that are so vastly different than the logcat data I was getting? I expected some difference, but not that huge.