With the announcement of WebGL last Friday I started to wonder about the relative performance of AS3 and JavaScript. This is what I’ve found.

With every major browser releasing much faster JavaScript engines there has been a flood of comparison tests pitting the speed of each browser against each other. This data is plenty easy to come by, so why not comparisons of AS3 against JavaScript? That seems much harder to find. What I found was limited to very old data, the newest of which was posted on oddhammer.com along with some data about Java Applets. Even this data reports scores for Flash 9 versus Firefox 2 since it is from 2006.

I decided to use their test suite unaltered to get updated numbers. My methodology was simple in that I simply used my 3.0Ghz Intel Core 2 Duo machine with Windows XP and 2GB of RAM to do the test with no other programs using any significant portion of the CPU. I repeated each test a few times and ended up with very consistent numbers. First, here’s the nitty gritty of individual tests in the oddhammer.com test suite:

JavaScript versus AS3 8-7-2009

JavaScript versus AS3 8-7-2009

Next is the total time taken by each to do all the tests:

JavaScript versus AS3 08-07-2009

JavaScript versus AS3 08-07-2009

The winners are clear: Firefox 3.5, Safari 4, and Flash 10. Then come the runners up: IE 8, Chrome 2, and Opera 9. IE 7 brings up the rear with a dismal performance.

So, JavaScript is indeed fast… in some implementations. The performance your users get will vary widely depending on their browser. Your application might take one second to complete a task on your Firefox development machine and 10 seconds on a user’s computer running IE 7. Sticking with just AS3 in Flash would obviate the differences between browsers and always yield very fast execution times. On the upside, IE7 is losing popularity, Opera is about to release version 10 with a faster JavaScript engine, and Google is about to release Chrome 3 with faster JavaScript engine. Perhaps by the time WebGL has arrived there will be ubiquitous speed amongst JavaScript implementations. I sure hope there is.

Raw data as Open Document Format (ODS) or Excel (XLS) format spreadsheet.