Performance of Silverlight vs Flash vs Javascript vs TraceMonkey
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!
Comments
-
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…
-
Serverside it does about 15 secs… But the machine isnt that powerful (a Xen VM actually).
—MV
-
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.
-
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
-
this above code can speed things a little.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."; } -
@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
-
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.
-
@Bart, that’s a very cool article :) Thanks for posting your results.
-
Interesting article. It seems Silverlight by far outperforms flash in this test. How come you have no performance comparison of the IE javascript engine.