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.

ASM > Benchmarking Code on Hardware

#7888 - funkeejeffou - Fri Jun 27, 2003 12:39 pm

Hi,

I've been wondering how to benchmark code on hardware(even on emulator though).
I would like to run a loop on my GBA, and with the help of a timer, I'd like to measurate it's performance. How can I output the timer value after the loop's end from the GBA to my PC?
I have a USB linker with a 128 MB F2A flash cart. Please tell me it is possible!!!

#7891 - niltsair - Fri Jun 27, 2003 3:25 pm

You'll have to print the result to screen using some tiles. If you really want the result on your computer then you could output results to SRAM (gamepak save game) and retrieve it afterward with your usb linker.

#7897 - Lupin - Fri Jun 27, 2003 7:50 pm

I already thought about that too, I think I'm going to write an simple test environment to perform speed tests.

You will need an int->string function to convert the result into an readable string if you don't want to use library functions (I prefer doing so, because I like to write my own funcs in asm).

#7924 - funkeejeffou - Sat Jun 28, 2003 7:17 pm

Thanks, I'm gonna try the SRAM thing then.
If anybody has done it before, could you please give us some hints?

#8756 - sgstair - Sat Jul 19, 2003 4:29 am

Here's some code to profile things:
Code:

   .GLOBAL ProfileBegin, ProfileEnd

@ void ProfileBegin(void);

ProfileBegin:
   mov      r3,#0x04000000
   add      r3,r3,#0x00100
   mov      r0,#0
   mov      r1,#0x0080
   mov      r2,#0x0084
   strh   r0,[r3,#8]
   strh   r0,[r3,#12]
   strh   r2,[r3,#14]
   strh   r1,[r3,#10]
   bx      lr


@ u32 ProfileEnd(void);

ProfileEnd:
   mov      r3,#0x04000000
   add      r3,r3,#0x00100
   mov      r0,#0
   strh   r0,[r3,#10]
   strh   r0,[r3,#14]
   ldrh   r0,[r3,#8]
   ldrh   r1,[r3,#12]
   add      r0,r0,r1,LSL #16
   bx      lr




Just slap it in a .s file and add the .o file to your makefile, then you can call the functions using the commented prototypes..

To get the profiler's overhead for wherever you put it:
Code:

u32 profileroverhead;
ProfileBegin();
profileroverhead=ProfileEnd();


If you have a multiboot cable for returning results I'd suggest using it, other than that printing the results to screen is only a few lines of code.

Hope this helps
-Stephen