To Optimize or Not to Optimize

It's time to benchmark our new game. The only place we really need to deal with speed is the game screen. I simply placed an FPSCounter instance in the GameScreen class and called its FPSCounter.logFrame() method at the end of the GameScreen.render() method. Here are the results on a Hero, a Droid, and a Nexus One:

01-02 20:58:06.417: DEBUG/FPSCounter(8251): fps: 57

01-02 20:58:07.427: DEBUG/FPSCounter(8251): fps: 57

01-02 20:58:08.447: DEBUG/FPSCounter(8251): fps: 57

01-02 20:58:09.447: DEBUG/FPSCounter(8251): fps: 56

01-02 21:03:59.643: DEBUG/FPSCounter(1676): fps: 61

01-02 21:04:00.659: DEBUG/FPSCounter(1676): fps: 59

01-02 21:04:01.659: DEBUG/FPSCounter(1676): fps: 60

01-02 21:04:02.666: DEBUG/FPSCounter(1676): fps: 60

01-02 20:54:05.263: DEBUG/FPSCounter(1393): fps: 61 01-02 20:54:06.273: DEBUG/FPSCounter(1393): fps: 61 01-02 20:54:07.273: DEBUG/FPSCounter(1393): fps: 60 01-02 20:54:08.283: DEBUG/FPSCounter(1393): fps: 61

Sixty frames per second out of the box is pretty good, I'd say. The Hero struggles a little, of course, due to its less-than-stellar CPU. We could use the SpatialHashGrid to speed up the simulation of our world a little. I'll leave that as an exercise to you, dear reader. There's no real necessity for doing so, though, as the Hero will always be fraught with problems (as will any other 1.5 device, for that matter). What's worse is the hiccups due to garbage collection every now and then on the Hero. We know the reason (a bug in direct ByteBuffer), but we can't really do anything about it. Let's hope Android version 1.5 will die a quick death soon.

I took the preceding measurements with sound disabled in the main menu. Let's try again with audio playback turned on:

01-02 21:01:22.437: DEBUG/FPSCounter(8251): fps: 43

01-

-02

21

01

: 23.457:

DEBUG/FPSCounter(8251):

fps:

48

01-

-02

21

01

: 24.467:

DEBUG/FPSCounter(8251):

fps:

49

01-

-02

21

01

:25.487:

DEBUG/FPSCounter(8251):

fps:

49

Droid

(2.1.1):

01-

-02

21

10

: 49.979:

DEBUG/FPSCounter(1676):

fps:

54

01

-02

21

10

: 50.979:

DEBUG/FPSCounter(1676):

fps:

56

01

02

21

10

: 51.987:

DEBUG/FPSCounter(1676):

fps:

54

01

02

21

10

: 52.987:

DEBUG/FPSCounter(1676):

fps:

56

Nexus

One (2.2.1):

01

02

21

: 06:

: 06.144:

DEBUG/FPSCounter(1470):

fps:

61

01

02

21

: 06:

:07.153:

DEBUG/FPSCounter(1470):

fps:

61

01

02

21

: 06:

: 08.173:

DEBUG/FPSCounter(1470):

fps:

62

01

02

21

: 06:

: 09.183:

DEBUG/FPSCounter(1470):

fps:

61

Ouch. The Hero has significantly lower performance when we play back our background music. The audio also takes its toll on the Droid. The Nexus One doesn't really care, though. What can we do about it? Nothing really. The big culprit is not so much the sound effects but the background music. Streaming and decoding an MP3 or OGG file takes away CPU cycles from our game; that's just how the world works. Just remember to factor that into your performance measurements.

0 0

Post a comment