Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm playing around with writing code for the Sega Genesis, which uses a Motorola 68000. I'm not an assembly code guru by any means so I'm writing in C and using SGDK. As it's slower than assembly, I'd like to be able to benchmark so that I can find slow spots and optimize them as much as I can. But I'm at a loss of how to do that. It doesn't look like the CPU has any timers or ticks that I can use. Any ideas?

One idea I've got is to find the code I want to benchmark and set it to run 1000 or 10,000 times, and have something visible happen when it's done. Because it's looping many, many times, the amount of time it takes is measurable with a stopwatch. Not the most friendly way, but it might be possible to use in some cases.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Look at the timer.h include, it has some of the basic timing functions. For reference http://code.google.com/p/sgdk/source/browse/trunk/include/timer.h?r=40

For example this function:

// return elapsed ticks from console reset (1/300 second based)
u32  getTick();

So, if you wanted to test a piece of code you would do this:

u32 start = getTick();
// place code here   
u32 dif = getTick() - start;
// 'dif' would be the number ticks that passed.
share|improve this answer
    
D'oh! I should've looked at the SGDK headers! I'll try that out and see if it works for me. –  DJCouchyCouch Mar 13 '12 at 15:08
    
@ShawnLeBlanc remember to run each piece of code a good number of times: excess of 1000. This will hopefully iron out any random conditions that may occur while the code is executing; and will avoid limitations regarding the timer frequency. (I'm sure you know this though - kudos for profiling first). –  Jonathan Dickinson Mar 13 '12 at 15:24
1  
@ShawnLeBlanc You can use a this clever trick and just #DEFINE something for your profiling builds (leave it empty for DEBUG/RELEASE). –  Jonathan Dickinson Mar 13 '12 at 15:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.