python and javascript performance compared v1

20 Sep 2008

Recently the WebKit folks introduced SquirrelFish Extreme, which claims Yet Another Breakthrough in javascript performance, especially when compared to other javascript engines.

And the PyPy guys posted some notes in their blog on Pycon UK, Javascript and the GIL, specifically:

Just got back from Pycon UK 2008 - here are some impressions. Both the keynote speakers Mark Shuttleworth (Canonical) and Ted Leung (Sun Microsystems) expressed their concerns about Javascript becoming so fast and prominent that it could displace Python in the future.

So how "bad" is python? How "good" is javascript?

So I went to SunSpider 0.9 got some timings from Safari 3.1. Then I also checked out the code via

svn co http://svn.webkit.org/repository/webkit/trunk/SunSpider/tests

A large number of the tests are from the The Computer Language Benchmarks Game. This is good, but the goals are a bit different. In CLBG, the goal is to "get done as fast as possible" using any standard extension available. My goal is to not use C extensions. For instance I'm not going to compare a javascript MD5 implementation via the python builtin C-extension. Also some of the implementations are just different (functional vs. OO style, use of an class/object vs. use of an native array type). I attempted to standardize and normalize best I could. most common is making compound strings. In Javascript you just use "+=" and add more. In python the standard idiom is to make a list of string pieces and then do a ''.join(pieces) at the end.

Anyways a few select tests were written for python, Highly likely I screwed up in some places too. Here are the results:

{
                           nop : 1.4 ms,  # cost of doing nothing
                      3d_morpth : 247.3 ms,

           access_binary_trees : 42.8 ms,   # uses lists, not objects
        access_binary_trees_oo : 116.0 ms,  # oo based
               access_fannkuch : 332.2 ms,

      bitops_3bit_bits_in_byte : 130.0 ms,
            bitops_bitwise_and : 289.5 ms,
           bitops_bits_in_byte : 310.7 ms,

         controlflow_recursive : 112.7 ms,

             crypto_md5_native :   3.4 ms,
             crypto_md5_python : 109.2 ms,
            crypto_sha1_native :   1.3 ms,
            crypto_sha1_python : 117.9 ms,

                   math_cordic : 262.5 ms,
             math_partial_sums : 133.5 ms,
             math_spectralnorm : 166.7 ms,

                    regexp_dna : 125.9 ms

                 string_base64 : 120.7 ms,
                  string_fasta : 184.9 ms,
         string_validate_input : 174.9 ms,
}

compared to Safari 3.1


    3d_ morph:              146.0ms +/- 1.3%
    access_binary-trees:        77.2ms +/- 4.3%
    access_fannkuch:           261.0ms +/- 1.3%


    bitops_3bit-bits-in-byte:   76.6ms +/- 11.6%
    bitops_bits-in-byte:       107.4ms +/- 3.7%
    bitops_bitwise-and:        188.8ms +/- 2.3%

    controlflow_recursive:           92.8ms +/- 3.3%

   crypto_md5:                 88.8ms +/- 5.8%
    crypto_sha1:                86.8ms +/- 4.7%

    math_cordic:             192.6ms +/- 3.5%
    math_partial-sums:       212.0ms +/- 2.1%
    spectral-norm:       89.6ms +/- 0.8%

    regexp_dna:                231.4ms +/- 3.7%

    string_base64:             111.4ms +/- 6.6%
    string_fasta:              201.4ms +/- 7.4%
    string_validate-input:     145.8ms +/- 4.6%

As you can see I didn't do the date, crypto or 3d ones because I am lazy. A few of the javascript are too JS-specific (unpack-code, tagcloud). nsieve-bits is a bit tricky for comparison since in python you can cheat since it has unlimited-precision integers so I'm not sure it's a good comparison. And some I didn't do since they require more work (lazy).

From this, javascript is faster than Safari 3.1.2 Firefox 3.02 is even faster. And both Safari and Firefox have major enhancements coming up that can double their performance.

You could say javascript is cheating since it has Just-In-Time compilers. Perhaps.... stay tuned as I hook up pysco


Comment 2008-10-08 by None

> In CLBG, the goal is to "get done as fast as possible" using any standard extension available. My goal is to not use C extensions.

Where does it say The Computer Language Benchmarks Game allows any standard C extension available?

Python :: TraceMonkey


Comment 2008-10-08 by None

Hi, thanks for the comment.

It doesn't explicitly say you can use C extensions, but I suspect anything in the "standard library" for a language is usable.

Javascript doesn't have much of anything for a standard library, while Python has a huge one (with a lot written in C).

My goal was to compare apples to apples, and just look at raw interpreter performance (pure python to pure javascript). The comparison isn't perfect since javascript has (or can has) a JIT compiler.


Comment 2008-10-10 by None

Use psyco.
ManiS