gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > How can i show fps?

#93684 - ETkoala - Thu Jul 20, 2006 5:55 pm

Is there any way to show the frames per second on screen? It will be useful to improve the code optimization ^^"

#93690 - spencer723 - Thu Jul 20, 2006 6:53 pm

Could you not increase a variable every VBlank and check the clock to see if a second has gone by then ouput it to the screen? After the second has gone by, just reset the variable and start again. I don't know how efficient that would be though.

#93695 - Lazy1 - Thu Jul 20, 2006 7:14 pm

I find it better to measure performance of specific functions in how long they take to execute in milliseconds.

Here's where you need to do:
-
- Set up a timer to increment every 1 millisecond
- In the start of your function assign a variable to the number of ms passed
- At the end of your function execution time will be ( current_ms_passed - initial_ms_passed )

Then just print out how long it took to the console.
Though, you'll need two timers one will have to overflow into timer #2.
Then you need an interrupt for timer #2 so when it overflows a variable is incremented with timer #2's value.

So, current_ms_passed = timer # 2 data + base_ms_counter.

#93708 - tepples - Thu Jul 20, 2006 9:12 pm

Or you can use VCOUNT (or whatever they named it on the DS) for the same effect without wasting a timer.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#93907 - LiraNuna - Fri Jul 21, 2006 10:52 pm

Code:


//on vblank irq:
++dsFrame;
if(dsFrame > 59) {
 FPS = renderingTime;
 renderingTime = dsFrame = 0;
}

// on main loop:
while(1) {
renderScene();
print(FPS);
++renderingTime;
}

_________________
Private property.
Violators will be shot, survivors will be shot again.

#94154 - ETkoala - Sun Jul 23, 2006 12:47 pm

LiraNuna wrote:


thanks ^^, it's easier to understand the code :)

#94419 - yayo - Mon Jul 24, 2006 8:14 pm

But VBlank will happen even when your code lasts 2 or more hardware vblank ticks in painting a frame, I think the true aprox is to measure the time you consume rendering a frame because vblank will happen exactly as the hardware specs tell us so :/
_________________
http://eduyayo.blogspot.com

#94458 - dovoto - Mon Jul 24, 2006 9:56 pm

yayo wrote:
But VBlank will happen even when your code lasts 2 or more hardware vblank ticks in painting a frame, I think the true aprox is to measure the time you consume rendering a frame because vblank will happen exactly as the hardware specs tell us so :/



In lira's code the renderTime variable is incremented once per game loop. Every 60 video frames this variable is saved (for printing) and reset, which gives you game frames per 60 video frames (or game frames per second). He could have used a one second timer instead of the vblank irq which perhaps would have been clearer (but a rather unecessary waste of a timer irq).
_________________
www.drunkencoders.com