a life of coding

Wednesday, December 10, 2008

JavaScript Performance

There are a lot of JavaScript performance benchmarks flying around out there. Some claim that Chrome shames the competition, others say that Firefox 3.1 is neck and neck with Chrome, others crown WebKit as the fastest of them all.

But what they never seem to do is compare them against other languages. One website, the Computer Language Shootout does, but it never seems to rate JavaScript particularly well. There are a few reasons for this. JavaScript has gotten a lot of attention recently and has thus been rapidly improving, and the CLS doesn't update very often. Tests are also written by different people, and folks who write JavaScript have never been the performance oriented crowd. Finally, the command line harness they use to execute JavaScript isn't representative of how users execute JavaScript.

So, what happens if we try to mitigate some of these? I picked a single test, rewrote it to run as a web page, and ran it using the latest version of browsers that can be considered stable. The results might surprise you.

n = 10
webkit [parallels/xp]1.0s
chrome [parallels/xp]2.0s

n = 11

Timings done on a Mac Book Pro 2.4 Gz Core 2 Duo / 4 GB RAM. Parallels/XP means running on Windows XP SP3 inside Parallels on the same computer.
WebKit is nightly build 39090.
WebKit [parallels/xp] is nightly build 39088.
jsc is built from svn rev 39090.
python is 2.5.1.
ruby is 1.8.6.

So, interesting things:

  1. The fastest JavaScript implementations are close to the speed of Java.

  2. The coming JavaScript implementations are substantially faster than Python or Ruby.

  3. WebKit is about twice as fast as jsc (the command line interpreter), so the Computer Language Shootout numbers will be inflated.

  4. Java 6 is substantially faster than Java 5.

So, I expect to see more web services written in JavaScript. Why? The argument for Python or Ruby has been that they are much more productive than Java/C/C++/C# that the performance of these languages isn't important. I certainly agree with this. However, JavaScript has about the same level of language productivity, and now has an implementation thats 18 times as fast as python and 32 times as fast as ruby. And you can use the same language across the board for web apps.

I also expect to start seeing desktop apps written in JavaScript. Why use a hacky python or ruby desktop app wrapper when you could use the best cross platform GUI kit there is? And, why bother with a local rails or django instance when you could do everything in a full MVC AJAX kit like Sproutcore or Objective-J?

At the risk of giving away the secrets to my sauce, desktop JavaScript is going to change everything. There are already a couple of frameworks out there (Jaxer, Titanium), but I think that there will be many more to come.

(PS: Lisp FTW!)


  • ynniv > the CLS doesn't update very often

    What information did you base that on?

    On Wednesday, December 10, 2008 the data file was revision 1.104.

    Today the data file is Revision 1.185 - that's about 4 updates a week.

    ynniv > Tests are also written by different people

    True for all the languages not just JavaScript.

    ynniv > folks who write JavaScript have never been the performance oriented crowdIf you think your JavaScript is better then contribute some better JavaScript programs.

    By Blogger Isaac Gouy, At 5/2/09 3:41 PM  

  • CLS appears to be updating much more frequently now, but the CLS JavaScriptCore benchmark results seem far out of line. As of May 5th, 2009, they have the following results for fannkuch:

    Python: 593.14 CPU seconds
    JavaScriptCore: 972.20 CPU seconds

    Which isn't even the same order of magnitude as the results that I obtained. The JavaScriptCore available in WebKit (and now Safari 4 beta) is much faster than the testkjs command line interpreter the CLS has compiled. Keep in mind that there is no official command line JavaScriptCore, and I have only been able to achieve half the performance of WebKit via compiling the newer jsc from the same source.

    I could contribute performance tuned JavaScript benchmark programs, but given the interpreter problem, these will have little effect on the JavaScript CLS results. The best way for me to showcase JavaScript performance is to post my own top to bottom results.

    By Blogger ynniv, At 5/5/09 9:05 AM  

  • JavaScriptCore was only measured on Debian AMD Sempron - and that hasn't been updated since the first couple of months of 2008.

    The current measurements are made on Intel Q6600.

    The current fannkuch measurements include Tracemonkey and V8.

    If you contribute JavaScript programs they will be run with Tracemonkey and V8.

    By Blogger Isaac Gouy, At 7/20/09 10:42 PM  

Post a Comment


Create a Link

<< Home