When I built the original PerformanceTest, I hacked it together quickly to meet a specific need I had at the time. As I used it, I found I needed more capability, and I became increasingly frustrated with both the messy code, and the poorly thought out API.
In response to feedback, and my own frustrations, I've completely rebuilt PerformanceTest to be more robust, extensible, feature-rich, *and* easier to use.
Core features:
- Track time, memory usage and retained (unreleased) memory for functions.
- Test rendering time for any display object.
- Write simple one line tests, or build formal test suites.
- Test suites can be built using inheritance or aggregation/composition.
- Trace simple text results, or access robust XML reports.
- Save XML and compare results between different versions of your code, or on different Flash players.
- Easily build logging classes to analyze or visualize results.
- Run multiple iterations of tests to get min, max, and deviation values.
- Run tests synchronously, or queue them to run them asynchronously.
- Listen for events from tests, test suites, and PerformanceTest.
- Integrates easily with TDD by facilitating the creation of tests for time, memory, and retained memory limits.
Here's a very simple demo:
In it's simplest form, you can use PerformanceTest in one line:
trace(PerformanceTest.run(myMethod)); trace(PerformanceTest.run(mySprite, "spriteRenderTest", iterations, loops));
You can go even simpler when testing methods, by using the ptest function shortcut:
trace(ptest(myMethod)); trace(ptest(myMethod, ["param"], "name", iterations, loops));
Want something a bit more robust? You can set up formal collections of tests using TestSuite. You can use these to set up suites of benchmarks to test different player platforms, or you can maintain them over the life of a project to track its performance profile by saving the XML Logs.
This is a beta. The docs are complete, but a little sparse. There are very few sample / demo files. It almost definitely has bugs. I also plan to add at least one more class/tool to it, for comparing XML logs.
Given that, I'd appreciate anyone who's interested checking it out and giving some feedback. Does it do what you need? Find any bugs? Is the API straightforward? How much more documentation do you need?
You can download PerformanceTest v2 here. As with pretty much all of the source code I release, it is licensed under the MIT license.
UPDATE: I just uploaded a new version with a working FLA. My apologies for the trouble with the original one. It also includes a *very* simple benchmark comparison tool.

Comments (14)
Thanks, Grant, this looks awesome. Especially if you don't use the FlexBuilder.
Posted by: bigfish at February 3, 2010 01:00 PMURL: http://dafishinsea.com
Hmm. Made me curious. So you use something like BitmapData.draw to test sprite drawing performance? Or you do it differently?
Posted by: wonderwhy-er at February 3, 2010 01:30 PMURL: http://wonderwhy-er.deviantart.com
Right, it uses BitmapData.draw(). This gives a pretty good idea of what the render time for a display object is on a single core. Not an exact value, but great for comparative metrics.
Posted by: Grant Skinner at February 3, 2010 01:34 PMURL: http://gskinner.com/blog/
I saw your tweet, and if you decide not to publish your thoughts on the future of Flash you will be my hero for about a week.
I value your opinion above most others that I've heard, but it would be a pretty pimp move not to beat this topic any further.
Posted by: cgortz at February 3, 2010 01:38 PMURL: http://www.chrisgortz.com
cgortz - sorry to disappoint. :)
Posted by: Grant Skinner at February 3, 2010 05:11 PMURL: http://gskinner.com/blog/
This is just in time for a project I'm working on. I used v1 quite a lot and found it very useful, so this is going to be even better.
For some reason I'm finding the FLA in the zip is failing to open in Flash CS4. Everything else unzipped fine.
Posted by: Ben Beaumont at February 4, 2010 07:15 AMURL:
So Powerful
Posted by: xiehuc at February 7, 2010 09:08 PMURL:
Same as Ben, the FLA is not opening in Flash CS4.
Posted by: Tronster at February 12, 2010 09:11 AMURL: http://tronster.com
Thankyou Grant! I was about to write my own really simple one when I found this, which is far better and really easy to use.
For those who can't open the flash file, it contains a dynamic text field with the instance name of 'outFld' and the document root class of PerformanceTestDemo
Posted by: Carly at February 13, 2010 12:07 AMURL: http://koali.com.au
Just wanted to say that I just found PerformanceTest tool set (20 minutes ago) and it is both very simple to use and invaluable. Thank you for releasing it!
Posted by: Alex at February 16, 2010 10:01 PMURL: http://blog.nodicerequired.com
I tried doing some memory usage checks for my unit tests they way you have, but it seemed like I kept getting false positive. Something as simple as:
var sprite : Sprite;
var(i : int = 0; i sprite = new Sprite;
sprite = null;
would say there was a leak.
I was going to try out my tests with your stuff, but I too cannot open with CS4.
Posted by: Brian at February 22, 2010 10:00 AMURL:
Im sorry to inform you that the Fla fails to open i both CS3 and CS4 on PC ??
Posted by: Henrik at February 24, 2010 10:26 AMURL:
In the PerformanceTest class there are a static method and protected member both named "queue", maybe we need different names?
Posted by: eidiot at February 28, 2010 08:09 PMURL: http://eidiot.net
Hey Grant,
Posted by: radykal at March 15, 2010 05:21 PMnice classes. But I have a question to you. How can I calculate the minimum system requirements(cpu,ram etc.) for his own flash movie. Could be the perfomancetest class a help for that?? I have already googled the whole day - no solution found!!
Thanks
URL: http://www.radykal.de