Slashdot Mirror


Comparing Browser JavaScript Performance

Thwomp writes "Over at Coding Horror Jeff Atwood has an interesting writeup on JavaScript performance in the big four browsers. He used WebKit's newly announced SunSpider to produce the results. If a probable anomaly in the IE7 results is overlooked, Firefox 2 is the slowest of the bunch. Atwood has also benchmarked the latest Firefox Beta, and its performance seems to be improved significantly."

42 of 134 comments (clear)

  1. A grain of salt by pwnies · · Score: 5, Interesting

    Take note of the tests for the latest Firefox beta though, notice that he's using a different system with .2Ghz more and he's on a 64 bit system versus a 32 bit. Although it's not a huge leap, it IS a difference. Different system different benchmark.

    1. Re:A grain of salt by Mini-Geek · · Score: 4, Insightful

      Take note of the tests for the latest Firefox beta though, notice that he's using a different system with .2Ghz more and he's on a 64 bit system versus a 32 bit. Although it's not a huge leap, it IS a difference. Different system different benchmark.
      Yes, it's a different system, so you shouldn't compare that FF3 number to the IE/Opera/Safari numbers, but you can still compare it to the FF2 number there (BTW that FF2 number is even a little slower than the one that all tests were run), which obviously shows that it's faster.
      --
      do {print "Mini-Geek Rules!\n";}
      until ($TheEndOfTheWorld);
    2. Re:A grain of salt by philwx · · Score: 3, Insightful

      Try a heads up between Firefox and IE after the average-joe user has had a few weeks to accumulate spyware.

      I'd like to see those results.

    3. Re:A grain of salt by Jeffrey+Baker · · Score: 4, Insightful

      I think this "benchmark" is deeply weird. It only exercises the pure execution paths, while pretty much ignoring all of the data structures that make a web page work. Every web app I've written or tried to optimize is limited not by time spent in javascript, but rather time spent manipulating the dom and drawing.

      I guess there's value in such a benchmark, but it goes against the conventional wisdom of Amdahl's Law. If JS execution accounts for only 10% of the runtime of your application, it will be of little value to make JS 20% faster. You must concentrate on the other 90%.

    4. Re:A grain of salt by Jeffrey+Baker · · Score: 2, Insightful

      I just profiled your page with Venkman and it seems that > 96% of the CPU time is spent in document.getElementsByName. Were you trying to prove my point?

  2. Hmmm by ubrgeek · · Score: 4, Funny

    > if a probable anomaly in the IE7 results is overlooked

    Like what? It didn't crash the system or it actually launched ;)

    --
    Bark less. Wag more.
    1. Re:Hmmm by jrumney · · Score: 4, Interesting

      The "probable anomaly" is that it is an order of magnitude slower than every other browser at string operations, which are a kind of important feature of Javascript. I'm not sure why he sees this as a probable anomaly, but not any other result where one browser does a lot worse than the others (no browser appears a clear winner or loser on everything, though Opera does come out in front more often than the others).

    2. Re:Hmmm by chrb · · Score: 4, Insightful

      He says: "What surprised me here is that Firefox is substantially slower than IE, once you factor out that wildly anomalous string result."

      To paraphrase: "What surprised me here is that Firefox is substantially slower than IE, once you manipulate the experimental data by removing something that IE is particularly slow at."

      And guess what? If you remove string ops, bit ops, and date ops, then Firefox is probably faster than IE. ;-)

    3. Re:Hmmm by gazbo · · Score: 3, Insightful
      Exactly because it's an order of magnitude slower. In all other tests it is a similar speed to all other browsers, then in one particular test it is ridiculously slower. There are no other tests or browsers that exhibit this behaviour, else I expect he'd have discounted them as anomolous also.

      There could be a good reason for the test showing poor performance - say IE is shit at string concatenation - and then the result reflects badly on IE. Or, it could be that for whatever reason the benchmark hits some strange edge case that virtually never crops up in normal usage, in which case the benchmark should be thrown out. But without further information you have to just treat the result as null. It's an unknown.

    4. Re:Hmmm by _xeno_ · · Score: 4, Informative

      IE's string concatenation is ridiculously slow. I've found that in all browsers (except Firefox) it's faster to use an Array, push() together the string elements, and finally join('') them together to create the final string.

      In Firefox, this is ever-so-slightly slower. In Internet Explorer, it's a good order of magnitude faster. (Depending on the length of the string. Concatenating a string 100 chars long together 10,000 times, I got a time of 13.7 seconds for plain old string concatenation ("string" + "string") versus .04 seconds for Array.push(). Firefox did the same test in .7 seconds using both methods.)

      The SunSpider tests appear to be using plain-old string concatenation. I'll have to try rewriting them using Array.push() and see what the result is. Doing that IE's performance would almost certainly beat Firefox.

      --
      You are in a maze of twisty little relative jumps, all alike.
    5. Re:Hmmm by morgan_greywolf · · Score: 2, Insightful

      IE wouldn't be faster than that much faster than Firefox 2, and no faster than Firefox if we 'filtered out' this anomalous reading. Assuming the string operations took 1.5 seconds (a nice round number in between Firefox's and Opera's times), we could subtract 12.9 seconds from IE's overall time of 21.2 seconds and arrivate at 8.4 seconds, putting it neck-and-neck with FF3 and still less than 25% faster than FF2's performance. FF2 is slow, but he makes it sound like FF2 sucks badly and it's just not that bad.

      That being said, one can't be sure that IE7's string reading was 'anomalous' without significantly more data.

      Also, I wouldn't make that much of the difference between Vista 32 and Vista 64 or between a 3.0 Ghz and a 3.2 ghz Core 2 Duo. Browser performance is likely extremely similar on both systems for all browsers, with the possible exception of IE7's (I have a sneaking feeling the 'anomalous' reading is an issue particular to 32-bit Vista)

    6. Re:Hmmm by mulveling · · Score: 5, Informative

      I've done some work before that required concatenating very large strings in Javascript, and the code was certain to be run in IE by our users. It was clear to me from the observed performance, that when you use the "+" or "+=" operators to build a large string from many smaller strings, IE does not attempt to optimize things under the hood with a String Buffer. In fact, *every* "+/+=" operation seems to allocate an entirely new String object to contain the result. Problem is, most of those Strings are intermediate results that will just end up get tossed by the garbage collector, and hence their allocation was for naught. A quick analysis of this means that we're looking at a total memory allocation cost on the order of N*N, which leads to very unreasonable performance when you're looking at concatenating 1000+ strings. From scanning the SunSpider string benchmarks, it looks like the specific benchmarks that IE has trouble with are indeed using the +/+= ops to build big Strings.

      Fortunately, there are workarounds. The easiest is put all the component strings you wish to add together into an array and then call join('') on the array to build the result string. This executes much, much faster in IE and should be fast in the other browsers as well. Before I figured out the join('') "trick", I implemented a scheme to add the component strings in a much more optimal order...the N^2 cost is only if you add them in a naive, left-to-right manner. By pairing up adjacent components and adding, you get N/2 intermediate results. Repeating the pairing process on these intermediates, and over again until you have your 1 final result, the allocation cost is only N*Log(N), which is far FAR better than N*N. Incidentally, this is similar to the "Russian Peasant Algorithm" technique used to optimize the addition of N numbers on massively parallel processors...whereby you can reduce the cost of N additions from N to Log(N) time assuming there are enough processors (N/2) on hand. When I learned about the join(), I compared its performance to the Russian Peasant technique and got very comparable results in IE. Weired, since if join() were using a StringBuffer under the hood (like it should), then its performance should be O(N), not N*Log(N)...

      Anyways, in summary - yeah it sucks hard that IE does that, but it's easy to workaround once you know what's up (gee, that's true in so many cases with IE quirks).

    7. Re:Hmmm by smittyoneeach · · Score: 2, Interesting

      This is speculation, but I think that the browser may use the COM MicroSort VBScript Regular Expressions 5.5 library, at c:\WINDOWS\System32\vbscript.dll, for doing regular expressions.
      If that's true, (and I figure someone will calibrate me if I'm wrong) that could explain an apparent performance anomaly, if the browser farms out the string manipulations to another process.

      --
      Get thee glass eyes, and, like a scurvy politician, seem to see things thou dost not.--King Lear
    8. Re:Hmmm by tdelaney · · Score: 3, Interesting

      I can attest to IE's crap string operation performance.

      4.5 HTML file, mainly consisting of one very large table. Took about 1 minute to render in IE, using about 80MB RAM. Was asked to lay it out in a more useful way. I went the fairly simple route - once it was fully loaded, I used JavaScript to lay it out better.

      Original attempt was to just use innerHTML and string operations (couldn't remember the DOM commands, too lazy to look them up). The main bit was a single substring() on the div containing the large table (actually stripped off everything around the table).

      The time to render the page jumped to 10 minutes! Memory use jumped sharply as well (largely because I was duplicating the table ... d'oh!). Cutting out that single substring operation dropped it back to 1 minute. Changing over to DOM manipulation left it at 1 minute.

      For comparison, Safari 3 on Windows rendered the entire page in 5 seconds, whether I used innerHTML and substring() (including the duplication mentioned above) or DOM manipulation. Safari used a bit more memory than IE though (worst case 215MB compared to 200MB).

  3. Ooh ooh let me guess by The+MAZZTer · · Score: 4, Funny

    With NoScript, Firefox's performance easily soars above the rest?

    1. Re:Ooh ooh let me guess by greg1104 · · Score: 2, Insightful

      Yeah, what's far more important to me than "how fast does this browser run Javascript?" is "how easily does the browser non run Javascript?"

  4. Vista + ie7 took hours! by mseidl · · Score: 5, Funny

    <html>
    <body>
    <script type="text/javascript">
    var i=0
    for (i=0;i<=10;i++)
    {
    document.write.UAC("Cancel or Allow?");
    document.prompt("Yes, No, Maybe?);
    }
    </script>
    </table>
    </body>
    </html>
  5. Opera by QuietLagoon · · Score: 2, Insightful

    Looks like they are finally getting their javascript act together. After being a sore point for so many years, a working javascript in Opera will be welcome.

    1. Re:Opera by whitehatlurker · · Score: 2, Informative
      Each of the individual tests work under Opera 9.25.

      There is an error in the aggregating mechanism of the benchmark. Otherwise, it would work in the current Opera as well.

      --
      .. paranoid crackpot leftover from the days of Amiga.
    2. Re:Opera by ed.markovich · · Score: 3, Funny

      Looks like they are finally getting their javascript act together. After being a sore point for so many years, a working javascript in Opera will be welcome. I am just curious as to what you're talking about. I've been using Opera for a while now and have not noticed it having any JS issues.

  6. Bah humbug! by SirJorgelOfBorgel · · Score: 5, Informative

    What an absolutely horrible speed test.

    First off IE6 is not tested, while it is still the most used browser. Also Opera 9.5 is not ready, it has so many bugs it just isn't funny anymore. Many sites break that worked fine in Opera 9.2.

    But let's get to the good stuff. Yes in pure JavaScript like this, IE might be faster than Firefox. But in real world situations it clearly isn't. There is no test done on layout manipulation (and such) using JavaScript. Internet Explorer is notoriously horrible at this, especially if you use it combination with PNG's with alphachannel or complex CSS. Not to mention if you have to use JavaScript hacks because of IE6's lack of CSS support for the simplest things.

    Funny is also how almost all JavaScript library speed tests I've seen put Internet Explorer far behind the others.

    In 'real world' JavaScript performance Opera and Safari would be the winners, where I'd choose Safari as absolute winner, as Opera gains a lot of redrawing speed by cutting corners it should not cut which often result in display corruption (ie, the type that goes away when you force a redraw by minimizing and then maximizing the window again, or moving another window over Opera and then away again). Quite a bit behind in speed after Safari and Opera would be Firefox, followed even further back by Internet Explorer.

    As a developer I still prefer Firefox for development though. Webkit is awesome, but the Safari GUI just plain sucks. Opera... hmm, I like it on my mobile devices, but it's just too weird for the desktop (what, textarea's don't even support scrolltop? wth!)

    1. Re:Bah humbug! by Phroggy · · Score: 4, Insightful

      First off IE6 is not tested, while it is still the most used browser. The WebKit team released a test suite, they didn't release test results. If you want to test IE6, then test IE6!

      Yes in pure JavaScript like this, IE might be faster than Firefox. But in real world situations it clearly isn't. There is no test done on layout manipulation (and such) using JavaScript. Internet Explorer is notoriously horrible at this, especially if you use it combination with PNG's with alphachannel or complex CSS. This is intentional. This is specifically a JS speed test, not a DOM speed test. If IE's DOM handling is horribly slow, that's a different issue - not an unimportant one, but a different one. This test is really deigned for browser developers, not users, and that's important: while users don't usually care about specific implementation details and just want an overall faster experience, developers can only focus on specific implementation details. Thus, developers interested in improving JavaScript performance need to be able to look at JavaScript performance without being thrown off track by DOM problems, which are probably the responsibility of a completely different team of developers. JavaScript developers probably can't fix DOM problems, just as DOM developers can't fix JavaScript problems.
      --
      $x='S24;r)>63/* h@<5+oZ)32"5cz';$me='phroggy'x$];
      $x=~y+ -xz+\0-Tx+;print$_^chop$me for split'',$x;
  7. Some more data ... by foobsr · · Score: 2, Informative

    here

    AMD Athlon 64 3200+, 1GB, Ubuntu 7.04, using FF for 4 hours, listening to last.fm.

    CC.

    --
    TaijiQuan (Huang, 5 loosenings)
  8. client side javascript will become our enemy by icepick72 · · Score: 2, Insightful

    Because of the incompatibilities and different bugs between browser JavaScript implementations for God's sake let's not have a world where client-side JavaScript is so fast we use it for everything. Development time will increase one more fold for each browser you want to support, and sometimes additionally for each minor version It will be hell on earth I predict.
    My basic rule of thumb has also been that client scripting should enhance and application but not be required for the application. In other words with JavaScript disabled the application might act rudimentary but will still produce results.

    1. Re:client side javascript will become our enemy by gazbo · · Score: 4, Informative
      Incompatibilities are disappearing at an alarming rate. Nowadays it's perfectly possible to develop a complex script on FF (appealing because of Firebug) and expect it to work with minimal if any modification on IE and Opera. Sure there are browser-specific functions, but they are almost invariably easy to avoid; the only real exceptions I can think of are different XML DOM methods, especially WRT namespaces.

      Compare it to the days of IE5.5 vs Netscape 6 (the worst browser ever released) vs Netscape 4.7 and you can see what huge progress has been made.

    2. Re:client side javascript will become our enemy by SirJorgelOfBorgel · · Score: 4, Insightful

      Oh really? JavaScript is not that hard to get to work correctly cross browser. I spent a LOT more time changing CSS things to work nicely than I do on JavaScript and I do use a lot of JavaScript. If you use a decent JavaScript toolkit, like for example jQuery, it's even faster and you hardly have to worry about it at all. For any nice advanced stuff you simply have to use JavaScript, and that's what it's there for. You want to disable JavaScript? That's fine by me, but you WILL be missing out. Really, what's next, catering to people who don't have CSS? Sure there are a lot of people who think sites should still work and look readable without CSS, but really, that depends on the market segment of the website. You can't make rich websites without CSS and JavaScript. Simple. Not every site can get away with looking like Google.com, it depends on the target audience and the content.

    3. Re:client side javascript will become our enemy by truthsearch · · Score: 2, Informative

      Nowadays it's perfectly possible to develop a complex script on FF (appealing because of Firebug) and expect it to work with minimal if any modification on IE and Opera.

      I can second this statement. With libraries like prototype, and others that build on top of it, cross-browser development is simplified. The libraries take care of many of the differences between browsers, leaving the developer to work on the actual features.

    4. Re:client side javascript will become our enemy by s4m7 · · Score: 2, Insightful

      Really, what's next, catering to people who don't have CSS?

      That's exactly why CSS exists... to separate content from layout/display characteristics. You can make an entirely graphical-button image-chopped page with all kinds of rollover goodness, and as long as you write your (x)html and CSS properly, it will break down fine in a text or mobile browser. Using techniques like image replacement is critical if you want your flashy website to be accessible to people using screen-readers or mobile browsers.

      This of course assumes that your site has some kind of content, other than just pure uncategorized imagery.

      Otherwise you could just put all your images in a table, put no alt attributes in and who cares? Oh, only the 40 million blind people in the world, and anyone who would want to use your site from a mobile device. Ahh, but those people probably aren't in your "target market" are they?

      --
      This comment is fully compliant with RFC 527.
  9. better idea by ILuvRamen · · Score: 2, Insightful

    Why don't people just stop making ridiculously complicated pages? Have you seen the yahoo hompage? Aol's is even worse. And Ebay's is a ridiculous nightmare. I don't who thought that looked good or thought people will look at or read that much but they should be fired. No browsers in the world could render those pages in under a second the way they're supposed to look. Plus remember that like 99% of page load slowness is from ad servers failing to load the ads fast enough

    --
    Google's Super Secret Search Algorithm: SELECT @search_results FROM internet WHERE @search_results = 'good'
  10. lynx beats them all, 17 ms to pass test by ls671 · · Score: 2, Funny

    I tried the same benchmark with my browser and it seems to beat them all, only 17 ms to pass the test !!!

    ~$ time lynx -dump http://webkit.org/perf/sunspider-0.9/sunspider-driver.html
    SunSpider JavaScript Benchmark (In Progress...)

    real 0m0.017s
    user 0m0.001s
    sys 0m0.004s
    ~$

    --
    Everything I write is lies, read between the lines.
    1. Re:lynx beats them all, 17 ms to pass test by ceoyoyo · · Score: 2

      That's 17 ms to TAKE the test. I expect Opera 9.5, which the author says couldn't pass the test, also did quite well in test taking time.

  11. Firefox through Wine by etymxris · · Score: 3, Interesting

    Bizarrely, Firefox for Windows running through wine runs faster than native Firefox. The wine installation doesn't have any add-ons though, so that might be the difference. Wine version is 0.9.51 and windows firefox version is 2.0.0.9, same machine as my post above.
    Wine results. Native results.

  12. The JIT compiler isn't in JavaScript yet. by Animats · · Score: 4, Interesting

    FireFox was supposed to be getting a JIT compiler for JavaScript. It's the one from the Flash player, where it runs ActionScript. That's apparently now expected in 2008. Then we'll see some real improvement.

  13. Good one by glwtta · · Score: 2, Insightful

    You know, it's cute to refer to "the big four" browsers, but you could've at least listed what you think those are - we are not mind readers.

    Had it been "the big one and the one that just edged into relevance", then most people would know what you meant.

    --
    sic transit gloria mundi
  14. And the winner: Linux by tcdk · · Score: 4, Informative

    Okay, maybe not, but this is my numbers:

    WinXP Firefox 2.0.0.11: 18.8s
    WinXP Internet Explorer 7.0.5730.11: 33.1s (same issue with the strings performance)
    Ubuntu Firefox 2.0.0.6 (yeah, well): 15.3s

    I only have opera running on my WinMobile Dell Axim v51x PDA and it's currently running, it seems to be 30-40 times slower than the desktop, so I'll not be waiting before I post...

    --
    TC - My Photos..
    1. Re:And the winner: Linux by tcdk · · Score: 2, Funny

      I only have opera running on my WinMobile Dell Axim v51x PDA and it's currently running, it seems to be 30-40 times slower than the desktop, so I'll not be waiting before I post...


      Okay, it wasn't that bad - it finished in 317.8s. So 15-20 times slower. I was actually surpriced that it managed to run to the end.
      --
      TC - My Photos..
  15. It's Flash by CrazedWalrus · · Score: 4, Interesting

    Firefox, for me, is really stable unless Flash is involved. Add Flash to the mix, and it goes down faster than a two dollar whore on a Friday night. By the way, so does Opera, but not quite as often. Close though. Just try watching 4-5 videos on YouTube.

    I think Flash is the biggest DoS in the history of the web and Adobe really needs to take a good look at it. With all of these Flash ads and Flash-based video players, it really is a critical issue. Using adblock is an absolute must in my book, just to keep the browser running. My bet is some sort of resource leakage, since it happens over time -- like when watching several YouTube videos. It doesn't crash on the first or second one, but you're courting disaster on the third and above.

    By the way, is there any way for FF to handle plugin crashes gracefully, i.e. *without* bringing down the browser with it? Maybe running it in a separate process somehow and just putting up a "broken image" sort of placeholder?

    1. Re:It's Flash by cheater512 · · Score: 3, Funny

      Seamonkey + Flash on my old P3 laptop is fine.

      If by fine you mean freaking bloody slow.
      Flash designers wouldnt know speed if it slapped them with a large trout.

      YouTube is good. It can handle a video pretty well (occasional frame dropping).
      Ads and many other things will reduce the computer to a crawl instantly.

  16. Compare JavaScript Frameworks by Dekortage · · Score: 3, Interesting

    If you run the MooTools Slickspeed tests in different browsers, you find something interesting:

    • jQuery is the fastest JavaScript framework in IE6 and 7, and the slowest in FireFox, and middle-of-the-pack in Safari.
    • MooTools is the fastest in Firefox and Safari, and slowest in IE.
    • Prototype is generally slower than the others, particularly in Safari, and frequently doesn't perform the tests correctly.

    jQuery also claims to be the most accurate, though who knows for sure.

    --
    $nice = $webHosting + $domainNames + $sslCerts
  17. Just a note: it wasn't "supposed" by ESqVIP · · Score: 2, Insightful

    AFAIK, Tamarin was since the beginning scheduled for Gecko 2 (i.e., Firefox 4). So, don't worry, it's not like it didn't make for Fx3, it wasn't supposed to be on this week's beta at all.

  18. The actual problem... by encoderer · · Score: 4, Informative

    The actual problem is the way JScript does string concatenation.

    When you concatenate 2 strings in JScript, it determines the size of the buffer needed, allocates the buffer, does the concatenation, and returns the result to the caller.

    Which works fine, until you start putting some load on those old tires...

    x = 'some';
    y = 'string';
    z = 'here';

    testString = x + " " + y + " " + z;

    (Ignore that nobody would actually write code JUST LIKE THAT, they would just add a trailing or leading space to the x, y & z strings. But concatenating a result with some white space is not abnormal.)

    Now, just think about what this is actually doing under the hood..

    1. determine len of x (4) plus len of " " (1) = 5
    2. Allocate new buffer(5)
    3. Concatenate, assign result to temp
    4. determine len of temp (5) plus len of y (6) = 11
    5. Allocate new buffer(11)
    6. Concatenate, assign results to new temp, destroy old temp
    7. determine len of temp (11) plus len of " " (1) = 12
    6. Allocate new buffer(12)
    8. Concatenate, assign results to new temp, destroy old temp
    9. determine len of temp (12) plus len of z (4) = 16
    10. Allocate new buffer (16)
    11. Concatenate, assign results to testString

    So, to concatenate relatively little string data, 3 temporary buffers were needed and 4 separate allocations were done.

    It works fine, right up to the point where it doesn't :)

  19. Vista + IE 7 vs Ubuntu 7.10 + FF 2 by michaelwigle · · Score: 2, Informative

    I did the test on a dual-boot Intel Core 2 Duo 2.0 GHz with 2 GB RAM Comparing Vista and IE 7 with Ubuntu 7.10 and FireFox 2. Vista took 17461.6ms and Ubuntu took 12532.4ms for a 15% improvement.

    Here are the links to the full reports:

    Windows Results and Ubuntu Results