JavaScript Is Slow
JavaScript Is Slow
Written by Harry Fairhead   
Saturday, 17 December 2011

The battle lines are drawn up - JavaScript v Native. Some programmers are of the opinion that only Native code will do and C++ is the language to use. Is this a reasonable position given how much faster JavaScript has become?

JavaScript in the browser is getting faster and this has resulted in some claims that it is so fast you don't need anything else. Be it 3D games or complex simulations, there are examples of JavaScript doing an impressive job, but how much faster are competing technologies? How much of the machine are we throwing away by using JavaScript?

Joel Webber has performed some comparisons of JavaScript under various engines, Java, and native code in various environments. The benchmark used is Box2D, the widely used physics engine that is responsible for the way you throw in Angry Birds. The reason for the choice is that it is a complex piece of code that isn't amenable to easy optimization. It also happens to be available in many different forms, having been ported to al the major environments. No attempt was made to make the benchmarks running on different systems in any way comparable, but given the importance of the code it is reasonable to assume that they represent reasonable attempts at creating something efficient. This is a very real world comparison of how the different systems perform.

The benchmark was used to compare performance under native C++, Google Chrome's NaCl native API, Java and a hand translated JavaScript running on a number of browsers. Also JavaScript generated from C++ and Java were tested.

The tests revealed that the systems separated into three groups -  the native code at around 5ms, JVM code at around 10ms and JavaScript at around 100ms.



While the JavaScript might be impressively fast notice that it is more than 20x slower than the native code. 

Of the native code approaches, NaCl in Chrome17 was slower but comparable to raw C++.  Of the rest, the real surprise was that the spread of results caused by the different browsers wasn't as big as the difference between hand generated and auto generated JavaScript  - with the auto-generated being faster. The fastest performance in the JavaScript group was C++ code complied to JavaScript using Mandreel.

So JavaScript implementations are quite a way from reaching native code performance. Even the highly optimized Java JVM is roughly three time slower than native code.

Perhaps we should not be surprised by the results. However as with all benchmarks this is just an indication of the state of things - only one machine was used and one highly specify non-optimized task. The results will either back up your prejudices or be another piece of evidence you reject as spurious. 

More information

You can see all of the results and a full discussion of the methods used in

Box2D as a measure of runtime performance






Bitcoin MOOC On Coursera

The Princeton University course on cryptocurrency technologies, in particular Bitcoin, is now open to all comers on Coursera. It doesn't cost a penny piece, let alone a Bitcoin.

Imagine Cup Earth

The latest Imagine Cup competition for student coders around the world has been launched, this time with NASA as the co-presenter.

More News




Last Updated ( Saturday, 17 December 2011 )

RSS feed of news items only
I Programmer News
Copyright © 2015 All Rights Reserved.