Two Tips for Benchmarking.

In anticipation of throwing a ton of benchmark data at you, I am going to run through two tips on benchmarking in Actionscript. The purpose is to explain my techniques, give credibility to my own benchmark data, and to help point out some not-so obvios pitfalls.

Avoid the debug compile
The debug compile in Flex-builder is severely tainted with debug code. Optimizations that improve performance in a debug compile may not improve performance in a release compile. Depending on your version of flexbuilder you may need to publish a release version to compile with out debug code.

Isolate what your testing
This is a no brainer, but it needs to be said. If you want to know how long it takes to perform an opperation, but the opperation is too fast to measure in milliseconds its obvios to place that opperation in a for loop. The catch here is you must subtract the time of running the foor loop or you will taint your results.

example :
var i:uint=0, t2:int=0, t1:int=0, t0:int=getTimer();
for(i=0;i<_testScale; i++){
}
t1=getTimer();
for(i=0;i<_testScale;i++){
__test1();
}
t2=getTimer();
_out('function call time: '+((t2-t1)-(t1-t0))+'\n');

This is especially important for granular timing as you will see in my next post.

Leave a Reply