Benchmarking gotchas

Just a quick tip to get the numbers right when testing the execution time of your ActionScript code; you only get correct results if you follow two steps:

  1. Compile your code with the debug flag set to false (mxmlc: -debug=false). Otherwise your swf gets bloated with byte code used by the debug player.
  2. Always test your swf with the release player. Most developers have set the debug player as the default one, but it doesn’t reflect real world performance because it can be much slower. If the context menu has the option “show redraw regions” you are running the debug player.

If you are not aware of this you might unintentionally spent much time in implementing some clever optimizations which appear to run faster in the debug player, but perform worse in the release player. Here is an example for the sin/cos approximation:

Debug player Release player
Math.sin() + Math.cos() 340 ms Math.sin() + Math.cos() 142 ms
inline sin + cos approximation (high precision) 440 ms inline sin + cos approximation (high precision) 11 ms