Jump to content



Welcome to KnowledgeSutra - Dear Guest , Please Register here to get Your own website. - Ask a Question / Express Opinion / Reply w/o Sign-Up!
- - - - -

A Comparison Of Javascript Speeds In Different Browsers


7 replies to this topic

#1 Rigaudon

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 101 posts
  • Gender:Male
  • Location:<?php echo __FILE__; ?> in other words, right behind you.
  • myCENT:50.57

Posted 16 April 2010 - 12:22 AM

Hi everybody.

I did my science fair project on a comparison of javascript speeds between browsers for both strings and numbers.

The browser versions I worked with are:

Firefox 3.5
Google Chrome
IE 8
Opera 10.00
Safari 4.31.9.1

Here's the code that I used to calculate time for integers:
<script type="text/javascript">

var times = new Array(100)
for(x=0;x<100;x++){
	var start = new Date();
	start = start.getTime();
	var i = 0;
	while(i<=10000000){
		i++;	
	}
	var end = new Date();
	end = end.getTime();
	var difference = end-start;
//	document.write(difference);
	times[x] = difference;
}
document.write(times);
var total = 0;
for(var k=0;k<100;k++){
	total = total+times[k];
}
var avg = total/100;
document.write("<br />"+avg);


</script>

Here's the string script:
<script type="text/javascript">
var letters = Array();
letters[0] = "a";letters[1] = "b";letters[2] = "c";letters[3] = "d";letters[4] = "e";letters[5] = "f";letters[6] = "g";letters[7] = "h";
letters[8] = "i";letters[9] = "j";letters[10] = "k";letters[11] = "l";letters[12] = "m";letters[13] = "n";letters[14] = "o";
letters[15] = "p";letters[16] = "q";letters[17] = "r";letters[18] = "s";letters[19] = "t";letters[20] = "u";letters[21] = "v";
letters[22] = "w";letters[23] = "x";letters[24] = "y";letters[25] = "z";letters[26] = "A";letters[27] = "B";letters[28] = "C";
letters[29] = "D";letters[30] = "E";letters[31] = "F";letters[32] = "G";letters[33] = "H";letters[34] = "I";letters[35] = "J";
letters[36] = "K";letters[37] = "L";letters[38] = "M";letters[39] = "N";letters[40] = "O";letters[41] = "P";letters[42] = "Q";
letters[43] = "R";letters[44] = "S";letters[45] = "T";letters[46] = "U";letters[47] = "V";letters[48] = "W";letters[49] = "X";
letters[50] = "Y";letters[51] = "Z";letters[52] = "0";letters[53] = "1";letters[54] = "2";letters[55] = "3";letters[56] = "4";
letters[57] = "5";letters[58] = "6";letters[59] = "7";letters[60] = "8";letters[61] = "9";letters[62] = "`";letters[63] = "~";
letters[64] = "!";letters[65] = "@";letters[66] = "#";letters[67] = "$";letters[68] = "%";letters[69] = "^";letters[70] = "&";
letters[71] = "*";letters[72] = "(";letters[73] = ")";letters[74] = "-";letters[75] = "_";letters[76] = "=";letters[77] = "+";
letters[78] = " ";letters[79] = "|";letters[80] = "]";letters[81] = "}";letters[82] = "[";letters[83] = "{";letters[84] = ":";
letters[85] = ";";letters[86] = "'";letters[87] = "\"";letters[88] = "/";letters[89] = ".";letters[90] = ",";letters[91] = "<";
letters[92] = ">";

var times = Array();
var count = 0;
for(var k=0;k<100;k++){
	var starttime = new Date();
	var start = starttime.getTime();
	var generatedString = "";
	var i=0;
	while(i<10000){
		var rand = Math.round(Math.random()*92);
		generatedString += letters[rand];
		i++;
	}
	var endtime = new Date();
	var end = endtime.getTime();
	var diff = end-start;
	times[count] = diff;
	count++;
}
var browser=navigator.appName;
var b_version=navigator.appVersion;
var version=parseFloat(b_version);
document.write("Times for "+browser+ "Version "+version+": <br />");
for(var k=0;k<100;k++){
	document.write(times[k]);
	if(k<99){
		document.write(", ");
	}
	if((k+1)%20==0){
		document.write("<br />");
	}
}
</script>

The results were actually very shocking to me.
(results are in milliseconds. Each number represents an entire loop- 10 million adds or 10000 length string)

Integers:
------------
Firefox 3.5:

45,45,46,45,46,46,46,45,46,46,46,46,46,46,46,46,45,46,45,46,45,46,46,45,46,
45,46,45,46,45,45,46,46,45,46,45,47,46,52,45,52,51,51,51,53,49,45,52,51,51,
52,51,51,52,51,51,51,52,51,52,51,52,51,53,51,47,46,51,51,51,51,51,51,50,52,
51,52,50,51,51,51,50,51,51,50,46,50,51,50,51,51,50,51,50,50,51,51,52,51,50
Average: 48.74 ms


Google Chrome:

117,114,112,113,112,109,109,108,109,109,109,110,109,110,109,109,108,110,108,111,
108,109,109,111,113,
110,109,108,108,109,109,110,109,109,109,113,109,110,108,108,110,108,109,110,109,
109,109,109,108,108,
108,108,109,108,110,109,108,108,108,108,108,108,110,109,109,110,109,108,109,108,
115,109,108,110,108,
109,108,110,108,108,110,108,109,108,108,109,109,109,109,109,112,110,108,109,109,
109,108,108,109,108
Average: 109.25 ms


Internet Explorer 8:

2728,2727,2720,2732,2709,2704,2703,2711,2716,2714,2704,2724,2729,2730,2728,2739,
2731,2727,2738,2714,2715,2722,2710,2717,2702,
2699,2729,5093,2756,2730,2734,2691,2692,2681,2695,2719,2704,2719,2694,2713,5117,
2734,2722,2725,2728,2713,2730,2727,2747,2715,
2702,2724,2708,2699,4436,2730,2721,2717,2704,2732,2714,2726,2722,2713,2723,2709,
2717,4523,2749,2733,2725,2736,2729,2719,2696,
2682,2711,2699,2696,2703,5031,2747,2732,2727,2709,2710,2716,2708,2710,2709,2711,
2710,2726,2736,4806,2747,2737,2733,2715,2711
Average: 2845.3 ms


Opera 10.00:
2536,2178,2124,2070,2081,2063,2114,2083,2101,2257,2144,2093,2079,2121,2211,2265,
2071,2069,2071,2067,2064,2061,2066,2064,2070,
2070,2067,2064,2061,2065,2062,2064,2069,2067,2067,2063,2063,2063,2057,2067,2065,
2084,2070,2067,2073,2060,2066,2064,2062,2070,
2066,2068,2065,2062,2062,2059,2063,2062,2069,2072,2063,2061,2057,2066,2060,2064,
2067,2062,2068,2066,2069,2064,2060,2069,2061,
2070,2063,2064,2060,2057,2065,2062,2059,2066,2062,2066,2059,2061,2064,2055,2067,
2061,2059,2065,2057,2063,2057,2061,2061,2063
Average: 2079.25 ms


Safari 4.31.9.1:
37,35,36,35,35,36,35,35,35,36,34,35,34,36,35,35,35,34,35,35,36,35,36,35,35,
35,35,35,35,35,35,34,34,36,34,35,36,36,36,35,34,35,34,35,35,35,34,35,35,35,
35,34,35,35,36,35,35,36,34,35,36,34,35,35,35,34,35,35,35,36,34,35,35,34,34,
35,35,34,34,35,35,36,35,35,35,35,36,34,35,35,36,34,36,35,35,35,35,34,35,36
Average: 35 ms

Strings:
Firefox 3.5:
4, 3, 4, 4, 3, 4, 4, 4, 3, 4, 4, 3, 6, 3, 4, 8, 4, 3, 4, 4,
4, 3, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4, 4, 3, 4, 4,
3, 4, 4, 4, 3, 4, 3, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 3,
4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4, 4, 3, 4, 3, 4, 4, 3, 4, 3,
4, 3, 4, 4, 3, 4, 4, 3, 3, 3, 4, 3, 4, 3, 4, 4, 3, 4, 4, 3
Average: 3.71

Google Chrome:
4, 3, 4, 3, 6, 4, 3, 4, 3, 4, 3, 3, 4, 3, 4, 3, 4, 3, 4, 3, 
4, 3, 4, 3, 4, 3, 3, 4, 3, 4, 3, 4, 3, 4, 4, 3, 3, 3, 4, 3, 
4, 3, 3, 4, 4, 4, 3, 3, 4, 3, 4, 3, 3, 4, 3, 4, 4, 3, 4, 3, 
3, 4, 3, 3, 3, 4, 3, 4, 3, 4, 3, 3, 3, 4, 3, 4, 3, 4, 3, 3, 
4, 3, 3, 4, 3, 4, 3, 3, 4, 4, 3, 3, 3, 4, 3, 3, 4, 3, 3, 3
Average:3.45

Internet Explorer 8:
31, 16, 31, 31, 16, 31, 31, 16, 31, 16, 31, 31, 16, 31, 16, 31, 31, 16, 31, 15, 
32, 15, 31, 16, 31, 16, 31, 31, 16, 31, 16, 31, 15, 32, 31, 15, 32, 15, 31, 16, 
31, 16, 31, 31, 16, 31, 16, 31, 15, 32, 15, 31, 32, 15, 31, 16, 31, 31, 16, 31, 
16, 31, 16, 31, 15, 32, 31, 15, 32, 15, 31, 16, 31, 31, 16, 31, 31, 16, 31, 16, 
31, 16, 31, 15, 32, 31, 15, 32, 15, 31, 16, 31, 31, 16, 31, 16, 31, 16, 31, 15
Average:24.49

Opera 10.00:
20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 15, 20, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 15, 20, 20, 20, 20, 20, 20, 20, 20, 20, 15, 20, 20, 20, 20, 20, 20, 20, 
20, 20, 20, 15, 20, 20, 20, 20, 20, 20, 20, 35, 20, 15, 20, 20, 160, 20, 15, 20, 
20, 20, 20, 20, 15, 20, 20, 20, 20, 20, 20, 20, 20, 100, 20, 20, 15, 20, 25, 20, 
15, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 15, 20, 20, 20, 20, 20, 20, 15, 60
Average: 22.25

Safari 4.31.9.1:
4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 
4, 5, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 5, 4, 3, 5, 4, 3, 4, 
4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 
4, 4, 4, 4, 3, 5, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
Average:3.94

I had always known IE was terrible in JS, but now, though these numbers will vary depending on the machine, I think it is safe to say that IE is just plain.... bad.

#2 web_designer

    "french rose sparkle under moonlight"...do you believe in the magic of moonlight??!!...

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,385 posts
  • Gender:Female
  • Location:US, CA
  • Interests:internet and the web
    reading books
    sport
    watching tv series
    drawings and art
  • myCENT:12.10
  • Spam Patrol

Posted 16 April 2010 - 12:23 AM

i can expect that. i work with java script from time to time, the best browser i use to see the effect is internet explorer, no matter what its version is internet explorer is the best browser to show java script. at least i don't have to activate java script manually like in firefox, or i get a blank page like the other browsers. but i still hate internet explorer ;)

#3 Rigaudon

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 101 posts
  • Gender:Male
  • Location:&lt;?php echo __FILE__; ?&gt; in other words, right behind you.
  • myCENT:50.57

Posted 16 April 2010 - 12:59 AM

View Postweb_designer, on Apr 15 2010, 07:23 PM, said:

i can expect that. i work with java script from time to time, the best browser i use to see the effect is internet explorer, no matter what its version is internet explorer is the best browser to show java script. at least i don't have to activate java script manually like in firefox, or i get a blank page like the other browsers. but i still hate internet explorer ;)

What I really hate about IE when developing is not only the speed, but when you have an interactive script that, say, changes the background color or alters html elements. You'd always get this "ACTIVE X- WARNING! THIS SITE MAY BE POTENTIALLY HARMFUL. ARE YOU SURE YOU WANT TO RUN THIS SCRIPT", or whatever it says, and you'd have to say "yes" every single time you reload the page.

The only slight plus for JS developers in IE is the built-in decoding box. However, this can hardly be called a plus, since firefox add-ons, like firebug, are much better, and the decoding box in IE is so vague anyways (object can't do that? What is that supposed to mean?)

#4 k_nitin_r

    Grand Imperial Poobah

  • Kontributors
  • PipPipPipPipPipPipPipPipPipPipPip
  • 1,114 posts
  • Gender:Male
  • Location:Dubai
  • myCENT:50.55

Posted 17 April 2010 - 04:55 PM

Hi!

I've been trying to use Google Docs from within Firefox, but the browser keeps locking up on the Javascript. After I switched to Google Chrome, Google Docs worked just perfectly. I wonder if Google Chrome has some kind of optimizations for the libraries that Google uses especially since Google's web-based applications are all that one can access when using the Chromium OS.

I haven't tried using Microsoft Internet Explorer for accessing Google Docs yet, but due to the large number of visitors who use Internet Explorer, Google would probably have a lite version.

The Microsoft Exchange email server has a lite version for non-Internet Explorer web browsers for accessing email via the web-based interface (abbreviated OWA for Outlook Web Access).

#5 Gammmae105

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 21 posts
  • Gender:Male
  • myCENT:45.99

Posted 17 April 2010 - 06:26 PM

Yeah, it was to be expected that IE was a crappy browser. Now we actually have proof for it. =P Btw, is there a way you can make another project except this time testing the FLASH scripts of the 4 different browsers? I can already see that Safari and IE will be down there in that aspect.

#6 Rigaudon

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 101 posts
  • Gender:Male
  • Location:&lt;?php echo __FILE__; ?&gt; in other words, right behind you.
  • myCENT:50.57

Posted 17 April 2010 - 06:48 PM

View Postk_nitin_r, on Apr 17 2010, 11:55 AM, said:

Hi!

I've been trying to use Google Docs from within Firefox, but the browser keeps locking up on the Javascript. After I switched to Google Chrome, Google Docs worked just perfectly. I wonder if Google Chrome has some kind of optimizations for the libraries that Google uses especially since Google's web-based applications are all that one can access when using the Chromium OS.

I haven't tried using Microsoft Internet Explorer for accessing Google Docs yet, but due to the large number of visitors who use Internet Explorer, Google would probably have a lite version.

The Microsoft Exchange email server has a lite version for non-Internet Explorer web browsers for accessing email via the web-based interface (abbreviated OWA for Outlook Web Access).

I would definitely think that Chrome has optimization for Google products, simply because Chrome was made by Google, and therefore, intended to be used with it.

I wouldn't be surprised if Firefox didn't fully support some functions since it's open source, meaning people can alter it. The good thing about being open-source is that one can always alter it again to fit what is required.

I don't know why one would bother using Outlook anyways, just use the web-based email. Microsoft does some pretty weird and unconventional things these days.

#7 Rigaudon

    Advanced Member

  • Kontributors
  • PipPipPipPipPipPipPip
  • 101 posts
  • Gender:Male
  • Location:&lt;?php echo __FILE__; ?&gt; in other words, right behind you.
  • myCENT:50.57

Posted 17 April 2010 - 07:41 PM

View PostGammmae105, on Apr 17 2010, 01:26 PM, said:

Yeah, it was to be expected that IE was a crappy browser. Now we actually have proof for it. =P Btw, is there a way you can make another project except this time testing the FLASH scripts of the 4 different browsers? I can already see that Safari and IE will be down there in that aspect.

Sure, I can try that, but my hypothesis would be that it depends on your system, and not predominantly the browser.

This is because Flash, as I know it, is a separate process from the browser, and the only link is in the initialization.

I will try it, however, and report the results when I'm done.

#8 Gammmae105

    Newbie [Level 1]

  • Kontributors
  • Pip
  • 21 posts
  • Gender:Male
  • myCENT:45.99

Posted 17 April 2010 - 10:27 PM

Cool. But yeah, I guess it can depend on the system, but as you know, Safari doesn't support flash as well as most other browsers such as chrome and Firefox, so that could also be an issue that deals with the actual browser and not the person's PC performance. But anyway, you're right, bc my PC has bad processing speeds and takes a while to load some flash objects, let alone play those objects. Let us know how your tests go. =)




Reply to this topic


This post will need approval from a moderator before this post is shown.

  


1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users