Hello habrayuzer. Now I'm trying to write a game on html5 + PhoneGap, of course, the performance is not very happy. So I decided to test all the browsers available for Android, including PhoneGap, for performance, this article will look at this cycle:
1. Calculations on pure javascript.
2. Rendering with DOM.
3. Rendering using Canvas.
4. Rendering using WebGL.
Actually, in this part, we will measure computations in JavaScript, although this is not a very important indicator, but since the physics of modern toys requires large calculations, JS can cut through performance.
And so we will multiply, extract the root and divide a million times, this is such a simple code:
for (i = 1; i <= 1000000; i++) { tmp1 = Math.random() * Number.MAX_VALUE; tmp2 = Math.sqrt(tmp1); tmp3 = tmp1 / tmp2; }
Full source: <html> <style type="text/css"> #mean { color: #8b0000; } </style> <body> </body> <script> var iteration = 0; var sumTime = 0; var init = function () { document.addEventListener('click', onClick); }; var onClick = function (e) { var i, tmp1, tmp2, tmp3, t1, t2, currentTime; t1 = new Date(); for (i = 1; i <= 1000000; i++) { tmp1 = Math.random() * Number.MAX_VALUE; tmp2 = Math.sqrt(tmp1); tmp3 = tmp1 / tmp2; } t2 = new Date(); currentTime = t2.getTime() - t1.getTime(); document.body.innerHTML += 'Time: ' + currentTime.toString() + ' ms <br>'; iteration++; sumTime += currentTime; if (iteration == 10) { document.body.innerHTML += '<div id="mean">Mean:' + (sumTime / iteration).toString() + 'ms </div><br>'; iteration = 0; sumTime = 0; } }; document.addEventListener("DOMContentLoaded", init, false); </script> </html>
')
Testing was conducted on a Samsung Galaxy Tab 2 P 5100 device.
New versions of popular browsers for Android, as well as popular platforms such as PhoneGap and Adobe AIR, participated in the testing.
Look what happened:Browser
| Version
| Milliseconds
|
Opera
| 12.1.3
| 896
|
Firefox
| 17.0
| 176
|
Chrome
| 18.0
| 76
|
Android borwser
| | 161
|
Phonegap
| 2.2.0
| 157
|
Adobe AIR
| 3.5.0.60
| 158
|
Dolphin
| 9.0.3
| 157
|
Now clearer:
Conclusion:
As you can see the opera hacked js performance at the root. Next comes ff, then the standard android browser, almost the same performance in PhoneGap and Adobe AIR, which is not surprising because they use the same WebKit.
Whoever doubted chrome in the first place, it turned out to be twice as fast as the standard browser, which doesn’t fit a bit in my head, because they both use WebKit.
I agree that such a simple indicator is not very informative, and is unable to fully display how real games will behave in these browsers, but the first step has been taken, and then everything will be just more interesting.
Update:
At the request of the workers, Dolphin was added, as we see all the WebKit chap gives out almost the same figures.