June 4, 2008

WebKit speeds

Posted in iPhone development, misc, using an iPhone tagged , , , , , , , , at 4:49 am by tetontech

A year ago I created a test to see how different JavaScript loop types compared based on speed. I compared a variant for loop against an invariant for loop and the for each loop. The test results, which can be found in the book Oracle Database Ajax & PHP Web Application Development (Oracle Press) by myself and Michael McLaughlin, showed that for all of the browsers examined the for each loop was much slower than the already slow variant loop and that the invariant loop was significantly faster.
If we were iterating over the elements in an array or map a standard looking variant loop would look like

for(var i = 0; i < array.length; i++)

An invariant loop would be

var len = array.length;
for(var i = 0; i < len; i++)

and a for each loop would look like

for (var i in array)

While the original tests were looking for percent speed improvements within a browser achievable by selecting the different types of loops I thought it would be interesting to modify the test to report raw speeds in milliseconds and then compare various browsers.
The speeds reported here are for the fast invariant for loop over a series of runs.
Safari 3.0 – 98 milliseconds
WebKit 3.1.1 – 37 milliseconds
Firefox – 200 milliseconds
Firefox 3.0 RC1 – 28 milliseconds

The new WebKit shows a dramatic increase over the older Safari as does the new Firefox. WebKit appears to be nearly 3 times faster in this test than its’ older version used in Safari. This may be due to the changing of the JavaScript interpreter to SquirrelFish in the place of the older one. A discussion of SquirrelFish and why it is faster can be found at WebKit’sblog.
It will be interesting to see if this new version makes it into the upcoming iPhone OS 2.0. It would be fantastic if it was stable enough and did. Every bit of speed you can get on a handheld device is precious.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: