Optimize your Flex / Flash app with the AS3 performance explorer

For one week, Lucy and Martim are changing the algorithm used to calculate the OLAP cube in bime. In this task, performance is everything as the same line of code can be executed millions of times.

To help us, we build an application, open source (MIT), the "AS3 performance tester", that takes some operations (such as incrementing a variable) and measure the time consumed by the different options you can use to achieve the operation.

There are a lot of resources on the web about AS3 performance but none seem to embrace the whole problem. Enter the AS3 performance tester. With it, we are trying to build a comprehensive tool that demonstrates (with tests) which syntax for a particular task is the most performant in AS3.

But first things first with the usuals:

More Computing sins are committed in the name of efficiency than any other reason including blind stupidity”–W.A. Wulf

“Premature Optimization is the root of all evil.”-Hoare and Knuth

“Bottlenecks occur in surprising places, so don’t try to second guess and put in a speed hack until you have proven that’s where the bottleneck is.”- Rob Pike

Nevertheless, here we talk of the basic of the AS3 language. Things you do in your everyday programming. Do you know the faster way to loop over an array ? Do you know that division is slower than multiplication and slower than bitwise operations ?

Most of the time, to provide accurate metrics, we loop on the operation a number of times and we calculate the mean. This application will evolve to include more robust tests.

We also used the D.eval library to allow the user to enter 2 scripts and compare performance on the fly. It uses a kind of eval() function so the code is much slower than actual compiled code. Nevertheless, our tests, so far, show that the proportions are right: a script slower with the eval() will be slower when compiled. Nevertheless, we mark this feature as highly experimental as my understanding of what the D.eval do can give improper results.

the application

the source

the lighthouse project