Libgdx performance testing.

Sooo how would I test performance in Libgdx? I mean, I can’t really measure the time it takes to render, because I don’t start/end the rendering process. I only “send” data to GPU or something like that. I don’t “update” display and stuff like that. Are there methods built into Libgdx to test performance?

I tried measuring the time it takes to “render” my game. (you know, glclear, batch.begin, render, batch.end). With this, it takes ~300.00 something (1000000000 / 1000 seconds?). When I add my update game logic, it takes +2000.00 something.

What code are you using to calculate it. I think that you just arent dividing enough.


long oldTime = System.nanoTime();
//render();
long nowTime = System.nanoTime();

double time = (nowTime - oldTime) / 1000;

Nano * 1000 = Microseconds
Micro * 1000 = Milliseconds
Milli * 1000 = Seconds

Take a look at this post on how to measure the time it takes for your GPU do to stuff: http://www.java-gaming.org/topics/normal-for-glclearcolor-and-glclear-to-be-slower-than-the-actual-rendering/31748/msg/295350/view.html#msg295350

@Trollwarrior1 just replace all those * with / :wink:

For what you’re trying to do (and I think that you should be measuring in msecs)


double time = (nowTime - oldTime) / 1000000 // In milliseconds
// OR
double time = (nowTime - oldTime) / 1000000000 // In seconds  (would not recommend using this unit)

Heh, it was a lazy way of writing “1000 nanoseconds is one microsecond” but I guess it backfired… =P

It still doesn’t work, because I cannot put an entry to where the loop starts. It is kinda the same thing. Unless I’m wrong somehow…

Just use the method you were originally using except correct the time conversions. From the numbers you’ve given, rendering takes .3 milliseconds (300 microseconds) and when you add your update game logic, it bumps it up to 2 milliseconds (2000 microseconds).

I’m not sure if this completely solves your needs but LibGDX has a rudimentary built in FPS counter: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/FPSLogger.html.

I want to know how many fps my game can render each second. MAXIMUM number of frames. To render non stop.

Unless I’m misunderstanding you the info you want is provided by Gdx.graphics.getRawDeltaTime(). This gives you the time (in seconds) that the previous frame took to render. To get a useful value you’ll need to turn off vsync.