Monday, July 2nd, 2007

iPhone Javascript and spec benchmark

Category: iPhone, JavaScript, Performance

John Murch has been running some benchmarks on both his iPhone and MacBook Pro to get a comparison .

For example, JSSpeed:

iPhone

Try/Catch with errors 378
Layer movement 3078
Random number engine (Did not compute)
Math engine 3474

DOM speed Testing… (998/1000)
Array functions 1739
String functions 535
Ajax declaration 1089
Total Duration
10293 ms

Macbook Pro

Try/Catch with errors 5

Layer movement 33
Random number engine 28
Math engine 43
DOM speed 21
Array functions 10
String functions 11
Ajax declaration 8
Total Duration 159 ms

For more benchmarks check out his post.

Posted by Dion Almaer at 6:06 am
8 Comments

+++--
3.7 rating from 14 votes

8 Comments »

Comments feed TrackBack URI

Very cool! Thanks, John.

I’ve definitely noticed the speed difference anecdotally. I tried to put it through its paces with the Dojo Chart benchmark, but the iPhone is not Safari 3 and therefore doesn’t have SVG support.

Comment by Ryan Breen — July 2, 2007

I hope the iPhone-specific API is coming soon. I believe developers *can* create really cool apps within the Safari sandbox, but not without some addition to iPhone safari. Some offline support would be nice, and onpinch() etc. as well.

Here’s to Adobe porting Flash (and hopefully AIR) to iPhone soon.

Comment by G — July 2, 2007

“Random number engine (Did not compute)”.

What does that mean? Does iPhone has a Random number engine

Comment by pong — July 2, 2007

On an i-mate SP5, running Opera Mini produced the following:

Try/Catch with errors 12
Layer movement 79
Random number engine 128
Math engine 174
DOM speed 45
Array functions 483
String functions 48
Ajax declaration NOT RUN
Total Duration 569 ms

So I’d say Opera Mini (v 3.1) doesn’t do too badly either. Well, except it didn’t run the Ajax declration.

Opera Mini 4 (beta) gave the following results:
Try/Catch with errors 0
Layer movement 0
Random number engine 155
Math engine 74
DOM speed 37
Array functions 120
String functions 12
Ajax declaration 68
Total Duration 466 ms

Interestingly though, Microsoft’s Pocket IE running on my SP5 will only give results for the first test (Try/Catch with errors) giving that test a result of 2000!

But also note that these results were obtained with the phone connected via USB to a PC with internet.

Comment by William Luu — July 3, 2007

I did not get a response for the random number generator. I am not sure if it failed or was not able to calculate. Let me know if you DO get it to compute on an iphone.

Comment by John — July 3, 2007

A friend and I did our own testing and found something very interesting.

A call to a no-op function is taking an abnormally large amount of time. Something like 75ms for 1000 of them where in a desktop browser it’s taking around 1ms. We had a bunch of other tests centered around mootools and the canvas tag that all came out fairly equally slow and the guess is that there is just some global overhead to function calls that’s accounting for the general slowness rather than problems with particular API’s (whose core functionality seems quite fast for a small device when you subtract out the appropriate function overhead).

You can run the tests here: http://lowtidegames.com/test/shapesonly.html (note: it does send the results to our server for easily getting the results off the iPhone).

A sample iPhone run:

no-op took 0 milliseconds.
get context took 1 milliseconds.
canvas bunch took 11 milliseconds.
100 times empty loop took 2 milliseconds.
1000 times empty loop with nothing() took 74 milliseconds.
set fillStyle 100 times took 88 milliseconds.
set strokeStyle 100 times took 93 milliseconds.
100 strokes of 20px took 63 milliseconds.
100 10×10 fillRects took 38 milliseconds.
100 25 radius triangles stroked took 179 milliseconds.
100 25 radius triangles filled took 180 milliseconds.
100 25 radius triangles stroked with style each time took 277 milliseconds.
100 25 radius triangles filled with style each time took 271 milliseconds.
100 strokes of 10px with style each time took 78 milliseconds.
100 5×5 fillRects with style each time took 124 milliseconds.
line math 10000 times took 1456 milliseconds.

Comment by Casey — July 3, 2007

John, I just did your test page with a Treo650 & Blaze browser 3 and it said 0 milliseconds for everything.

Comment by Chris Phillips — August 2, 2007

Chris, it seems that your browser doesn’t support canvas tag.

Comment by Denis Perevalov — August 27, 2007

Leave a comment

You must be logged in to post a comment.