The latest stable version of Chrome browser at the time this article was written was 3.0.195.33. We will compare it to the current version of IE, which is 8.0.6001.18865. We started with Google’s own benchmark that is hosted at their site and is called V8 Benchmark Suite. The result differed from one machine to another, but the score of the Google browser was always about 38 times higher than the one of IE – very close to the numbers that Google is claiming. Of course, as much we believe in the accuracy of the tests, we wanted to use some independent benchmarking sites, too. After some research, we found some of the major ones are SunSpider JavaScript Benchmark and JSBenchmark. Their tests are a complex mixture of different tasks, including drawing, code decompression, encrypting and operations with arrays, dates and handling exceptions. As we expected, the difference between the two browsers was much smaller compared to Google’s own test, but it was again pretty impressive. The results differed from platform to platform, but overall the “SunSpider” test showed that Chrome is ten times faster, while the “JSBenchmark” reported that it is “only” seven times faster.
In order to conclude that Internet Explorer is much slower than Google Chrome in JavaScript performance though, we still needed more facts. As an alternative to the complex and heavy testing suites, we created a very short example with few array operations. We wanted it to be fairly simple and pretty close to real life examples. Basically, this piece of code assigned random numbers to an array of 20,000 items. Then we reversed the order of the elements. In the next two steps we sorted it in ascending and descending order. The script outputs the milliseconds needed for its completion. We did not expect a lot of difference in doing something so basic. Here is the code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>MentorMate JavaScript simple speed test</title>
<script type="text/javascript">
<!--
function testStart() {
var mySampleNumbers = new Array();
var now;
var start_time_mill;
var end_time_mill;
//gets the start date
now = new Date();
start_time_mill = now.getTime();
//assigning random numbers to an array of 20 thousand items
for (i=0;i<=20000;i++) {
mySampleNumbers[i] = Math.random();
}
//reverse the order of the elements in an array
mySampleNumbers.reverse();
//sort the numbers (ascending)
mySampleNumbers.sort(sortAsc);
//sort the numbers (descending)
mySampleNumbers.sort(sortDesc);
//gets the end date
now = new Date();
end_time_mill = now.getTime();
displayResult(end_time_mill - start_time_mill);
}
function sortAsc(m, n) {
if (m > n) {
return 1;
}
else if (m < n) {
return -1;
}
else {
return 0;
}
}
function sortDesc(m, n) {
if (m > n) {
return -1;
}
else if (m < n) {
return 1;
}
else {
return 0;
}
}
function displayResult(result) {
alert("Result: " + result + " ms.");
}
// -->
</script>
</head>
<body>
<form action="">
<p>
<input type="button" value="Start" onclick="testStart()" />
</p>
</form>
</body>
</html>
There were differences from PC to PC as with the other tests, but the tendency stayed the same. The time of completion of the tasks in Chrome was about six times faster than IE. This was the smallest advantage the Google browser had compared to the tests that were run so far, but it sounds pretty prestige for Chrome to have such a boost in performance for a really small task.
In conclusion, we can say that Google Chrome has set new standards for speed as far as JavaScript is concerned. Although the advantage the browser has might not be as big as Google claim in their advertising campaigns, it is something very impressive and gives the users additional speed for simple everyday tasks as we saw in the example above. We are looking forward to see the ninth version of Internet Explorer soon, as in the early discussions the developers show ambition to reach the level of performance that Chrome already has. The acceleration of the JavaScript engines for all the browsers can only bring benefits to users and contribute to the creation of richer, more complex Internet applications.
Leave a Reply