Saturday, July 01, 2006

Benchmarking Javascript - Is your browser slow?

Javascript code snippet
When writing an Ajax application the other day I was disappointed by how fiddly it was to parse the XML data in Javascript. I decided to opt to transform the XML into HTML using XSLT on the client browser using Google's Open-Source Javascript XSLT library. It quickly became apparent that the speed of transformation was noticably slower on my Powerbook G4 in Safari than in the Mozilla-based browser; switching to Camino produced no delays during transformation. Is Safari that slow at running Javascript? I set about finding out.

I wrote a simple Ajax benchmark to transform some XML contaning one hundred "records" into 100 lines of HTML. By timing how long the XSLT transformation took, I was able to compare the performance of the different browsers' Javascript engines on the same hardware. Here are the results (in seconds):

Powerbook G4 1.5GHz with 1Gb RAM - OS X 10.4.7
Safari - 4.5s
Camino - 1.6s
Firefox - 1.7s

iMac 2.2GHz Dual Core with 1Gb RAM - OS X 10.4.7
Safari - 1.3s
Camino - 0.6s
Firefox - 0.6s

Dell Pentium 4 3GHz 1Gb RAM - Windows XP Pro
IE6 - 3.0s
Firefox - 1.0s

Dell Pentium 4 3GHz 1Gb RAM - RedHat EL 4
FireFox 0.9s

What do these figures tell us? Broadly that Firefox's Javascript is fast and IE and Safari's is around two to three times slower. It would have been nice to benchmark the different operating systems on the same iMac, using Boot Camp or Parallels but I didn't have time.

I'm not claiming that these figures reflect the full gamut of tasks that Javascript could be used for. Usually Javascript scripts are so small that their execution time is pretty irrelevant. Javascript is, however, being used more and more to power "Web 2.0" applications, and the speed differences measured here are not the odd 5% here are there, they are 200 or 300% differences.

If you wish to try the benchmark on your browser then you can find the code here.

Labels: ,

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home