Performance of Silverlight vs Flash vs Javascript vs TraceMonkey

written by tobinharris on August 30th, 2008 @ 07:35 PM

Tim Anderson does a side-by-side comparison of Silverlight and Flash for calculating prime numbers. He has written the program in both platforms. I thought I'd add a Javascript version into the mix too. The results were as follows:

Calculating 1,000,000 primes

  • Silverlight: 0.42 secs
  • Flash: 1.22 secs
  • Minefield 3.1 Javascript: 4.75 secs
  • Safari Javascript: 5.75 secs
  • Firefox 2 Javascript: 7.08 secs

I actually thought that Minefield (Firefox 3.1 with TraceMonkey Jit) would be up there with Flash and Silverlight. I guess that the JS Jit works on hot paths and therefore couldn't find much to do?

UPDATE

@Shi posted another version in the comments with much improved times:

  • Minefield 3.1 Javascript: 1.88 secs
  • Safari Javascript: 4.99 secs

That's more like it!



kick it on DotNetKicks.com



Comments

  • Thomas Hansen on 30 Aug 23:34

    Hi Tobes, performance is much more than just execution time. I assume many sites will also think initial load time is just as important as the actual execution time. And in that area you should do a lot of really dumb things if your JS solution is worse than both Silverlight and Flex… PS! I’ve been trying to contact you quite a lot…

  • MV on 31 Aug 01:21

    Serverside it does about 15 secs… But the machine isnt that powerful (a Xen VM actually).

    —MV

  • Stefan on 31 Aug 15:03

    This isn’t a suited benchmark as JavaScript isn’t meant for number crunching anyway. However, I’m still a little disappointed after seeing FF3.1 performance.

  • shi on 31 Aug 16:51

    function countprimes(n) { n = n||1000000; var start = new Date(); var i,j,limit=0; var numprimes = 1; MAIN:for (i = 3; i<= n; i+=2) {

    limit =  Math.ceil(Math.sqrt(i)) + 1;
    return "Number of primes up to: " + n + " is " + numprimes + ", counted in " + elapsed + " secs.";
    }

    this above code can speed things a little. even if i

  • shi on 31 Aug 16:54

    
    function countprimes(n) {
       n = n||1000000;
       var start = new Date();
       var i,j,limit=0;
       var numprimes = 1;
       MAIN:for (i = 3; i<= n; i+=2) {
    
        limit =  Math.ceil(Math.sqrt(i)) + 1;
    
        for (j = 3; j < limit; j+=2) 
           if(i % j === 0) continue MAIN;
    
        numprimes++;
       }
    
       var elapsed = (new Date() - start) / 1000;
      return "Number of primes up to: " + n + " is " + numprimes + ", counted in " + elapsed + " secs.";
    
        }
    
    
    
    this above code can speed things a little.
  • Tobin Harris on 01 Sep 02:55

    @MV

    I know what you’re saying.

    But, I like HTML and I like the browser. I’d like to see it grow and evolve to be the ultimate platform. So, we need to see good benchmarks to have confidence. Therefore, I really hope to see Javascript run as fast as the “competition” for basic scripts such as this.

    @Thomas

    Thanks for the comments. Drop me another Skype when you’re on!

    @shi

    WHOA! Nice work.

    MineField: 1.88 secs Safari: 4.99 secs

    Javascript Kudos to @shi

  • Bart Czernicki on 09 Sep 09:29

    I took the code and multithreaded it inside Silverlight and netted about a 100% performance gain.

    http://www.silverlighthack.com/post/2008/09/07/Silverlight-MultiThreading-with-a-Computational-Process-(Counting-Primes).aspx

    I don’t think Flash/Flex has this and can be optimized this way. If that is true, multithreading gives Silverlight another notch in its favor.

  • Tobin Harris on 15 Sep 18:35

    @Bart, that’s a very cool article :) Thanks for posting your results.

  • Christopher on 25 Oct 03:44

    Interesting article. It seems Silverlight by far outperforms flash in this test. How come you have no performance comparison of the IE javascript engine.

Post a comment

Options:

Size

Colors