Is JavaScript Generated by Google Web ToolKit faster or slower than hand crafted Javascript?

In short there is no difference, but there is more to the story than that. Below are my findings, and I present them to you in a non-biased fashion and with no guarantee. This benchmark is un-comprehensive and so you will have to forgive me for possible errors. The benchmark has been run on Ubuntu 10.04 and Mac OS X 10.6 using FireFox, Chrome and Safari. It was also tested on the iPhone in Safari the Macintosh browser. (Part Two of the article is here Google Web Toolkit JavaScript Vs hand Crafted JavaScript benchmark Part 2) (Thanks to @Carl)





[ad#Adsence_inline_200*200]

I have used a sorting algorithm known as the bubble sort algorithm to benchmark the speed of both scripts and reproduced the same code in both Java (Google Web Toolkit) and JavaScript. Both pieces of code are almost identical but for the few syntax differences, to make this test as fair as possible. Each script is given the same array of numbers to sort, timers are setup to clock how long it takes to execute the sort() method in each case. Both scripts are then run 10 times to get the average time of execution. Below are the charted benchmark results where Google Web ToolKit generated JavaScript is green and handcrafted JavaScript red.

Benchmark Results

Click image to enlarge





Benchmark Conclusions

Well, as can be seen from the graph, there are some very positive results for browsers such as Chrome and Safari. Though (as expected) running both pieces of code in Firefox is extremely slow, due to the JavaScript engine used in the browser. However, with reports of a new webkit based JavaScript engine being developed for Firefox we should hopefully see some well needed improvement.





Safari on the iPhone shows some interesting results where GWT is faster than the handcrafted JavaScript. Now those results are not comprehensive as the version number of Safari is unknown, but it’s presumably an old version. Also the test was run on an iPhone emulator that comes with the Mac OS X development tools and iPhone SDK, though from what I understand it’s as good as the real thing.





I will be following up this article in the next week or two with benchmark results from Windows xp, Vista, 7, Symbian OS, and also Android as I am soon to be the proud owner of an Android aPad tablet device from Amazon. Hopefully it’ll be delivered before I move back down to Carlow.

(Part Two of the article is here Google Web Toolkit JavaScript Vs hand Crafted JavaScript benchmark Part 2)





Thanks for reading!

Benchmark screencast