Page: 1, 2  Next

Javascript Execution Speed
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
I've always wondered why complex javascript runs so differently in different browsers. To test the actual speed of the different browser's javascript engines, I created this simple loop, with a timer set to report in milliseconds how long it took to run through the loop 1,000,000 times.

I ran it on an AMD Athlon XP 1700 processor, with PC 2700 DDR ram. Obviously different motherboards, processor speeds and models, and memory types and speed, will dramatically change the times you get. If you want to test this for yourselves, simply cut and paste this code into a blank page, save it as js-time.htm or whatever, then run it.
:: Code ::

<html>
<head>
<title>Javascript Execution Time Test</title>
</head>
<body>
<script type="text/javascript">
var date1 = new Date();
var milliseconds1 = date1.getTime();
var j=0;
for (i=0; i < 1000000; i++)
{
j++;
}
var date2 = new Date();
var milliseconds2 = date2.getTime();

var difference = milliseconds2 - milliseconds1;
alert(difference);
</script>
</body>
</html>


I tried this on several Operating systems, all on the same machine. The differences are wide, between IE versions there's a noticeable difference:

Windows 98 IE 4: 770 [FAT32]
Windows 2000 IE 5.0: 691 [FAT32]
Windows 2000 IE 5.5: 770 [NTFS]
Windows XP IE 6.02: 942 [NTFS]

IE 4 and 5.5 were the most consistent, the times returned varied little from the above numbers. IE 6 varied a bit, as did IE 5.0.

As you can see, what makes the difference is how the javascript engine is handling the programming. In fact, the results are exactly what I would expect from seeing browsers work. IE 4 was not perfect but good, lightweight. IE 5 was quite improved. IE 5.5 was getting more complex, but still is very good. IE 6 starts bogging down again.

Because there are so many iterations, you can actually see how fast each browser's javascript engine handles the javascript it's been given.

Opera is the slowest by far, at between 2300-2600 on all OS's. Opera 6 was a few hundred milliseconds faster than 7.54.

[average times - varies widely run to run, by 10-200 milliseconds]
Win 98 Opera 6.04: 2360
Win 98 Opera 7.54: 2640
Windows 2000 Opera 6: 2260
Windows 2000 Opera 7.54: 2450
Windows XP Opera 7.54: 2500-2600

Firefox 1.0 comes at about 1450 for all OS's, almost exactly the same as Firebird 0.6 on windows 98, which was about 1590, suggesting the javascript engine has been improved slightly.
Mozilla 1.6 is about 1650, suggesting Mozilla is as slow as people think.

All these times vary significantly, by 5-100 milliseconds, that's depending I think on processor availability and useage.

These results are a function of processor speed primarily as far as I can tell, then secondarily how well written the browser's internal javascript engine is.

Opera will have to stop saying it's the fastest browser on earth, since this simple test shows that to be a flat out lie, in fact, I'd suggest Opera find a new business plan, obviously their current one isn't very good. The only slower one I found was Konqueror, which almost crashed on this, but then would sort of report some time.

Firefox on Linux 2.6 kernel on a 1 gigahertz machine with pc133 sdram came in at 3300 milliseconds, but that's a significantly slower machine, it's hard to compare unless you run the test on exactly the same hardware setup.

As always, myths and marketing have very little to do with reality, but, as I had suspected, and to Microsoft's credit, they do in fact have the best Javascript engine in the world. They do know how to program, even though their products don't always show that. I knew this already from watching complex scripts I've written run on the 3 browsers, but here's the actual empirical proof.

Firefox is however quite good, and is a strong runner up, in fact, if IE 6 slows down any more, and Firefox speeds up a bit, they'd be neck and neck, and, given that it doesn't give malicious scripts access to your Active X and so on like IE does, I'd say that it's a fair trade off, a little speed in exchange for a little security. As far as I'm concerned however, Opera should just abandon the desktop market, where they are after 5 years still barely breaking 0.25% market share, and free web developers from having to deal with yet another stupid Opera bug.
Back to top
minck
Status: Interested
Joined: 02 Nov 2004
Posts: 39
Location: Belgium
Reply Quote
I've heard from reliable sources, and come to believe, that ie's js engine is faster (and thus less prone to crashes / stabler) than ff or pretty much anything else out there, and it's nice indeed to see this fact confirmed in numbers. Not really anything useful I can do with this info, though, in a browser I only touch to clear up its bugs. Thanks for the script and the analysis.
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
:: Quote ::
in a browser I only touch to clear up its bugs


Same here, but I think for Firefox to get better, it's important that its weaknesses are also discussed.

The above script simply shows the physical speed difference in a very simple loop. I've written a few scripts [like this one] that completely bog down Firefox, grinds it to a halt, but run fine in IE, and in that case, Opera 7x. When you get to more complex JS, this difference becomes amplified dramatically, until the script basically fails. Which points to something more than just a simple speed difference in the Javascript engine, it suggests a fundamental weakness. And that's something I think Firefox/Gecko should address, since their CSS/HTML is easily the best in the world.

It's my suspicion that the corporate testing model can work pretty well when it comes to creating single objects like a javascript engine, since there are so many resources available to throw at the problem, real programming tools, real stress testing. Open Source has many of these, but I think the people who use them are more interested in deeper level functionality than something that in many ways is correctly considered to be mere eye candy. That's definitely how I've come to view Javascript, I use it for only very basic things, popups, a few other things. Except on techpatterns of course. But even there the site uses a lot less than it used a year ago [still have to cut out the old junk, too much JS].

In the case of the more complex script, Opera 7x runs that using essentially 0% of processor on Windows 2000, at about 250 mB DDR useage.
Firefox forces the OS to supply between 0-20+% processor capacity, with the same ram useage.
IE 5.5 also runs the script with essentially 0% processor useage [on an Athlon XP 1700 machine.]
Clearly there is an issue with Firefox's Javascript execution engine that needs to be corrected.
Back to top
vkaryl
Status: Contributor
Joined: 31 Oct 2004
Posts: 273
Location: back of beyond - s. UT, closer to Vegas than SLC
Reply Quote
Hey jeff - what was the thanksgiving script supposed to do to firefox?
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
It runs normally for about one cycle, then starts slowing down until it almost stops. If you compare it in IE or Opera it just runs on forever. Do you see anything different?
Back to top
vkaryl
Status: Contributor
Joined: 31 Oct 2004
Posts: 273
Location: back of beyond - s. UT, closer to Vegas than SLC
Reply Quote
Well, don't know what you have in mind for a "cycle", "slowing down", "running forever".... I let it run last night for what seemed like a half-dozen cycles, and it's running right now in another tab. No slow down, just running along happily....

[I remind you again: I'm the ONLY one who NEVER has bugs in games that kill off the rest of the world... it's probably a similar "gremlin"....]
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
that's really weird, on all my boxes always, on all versions of mozilla firefox I've ever installed the script bogs down.

I'm curious, can you let it run and tell me what the processor useage is in firefox [ctrl+alt+del - task manager - performance]? On my system it runs between about 2-20%, dropping to zero now and then when the script totally bogs down.

You're running this on XP, correct?
Back to top
vkaryl
Status: Contributor
Joined: 31 Oct 2004
Posts: 273
Location: back of beyond - s. UT, closer to Vegas than SLC
Reply Quote
Yes, XPPro SP1.

Runs between 1% and 38% usage "normally" (that is, while the script is running) - when I moved the scrollbar on another window, went up to 100%, down to 53%, back up to 93%, then down to 1% when I quit with the scrollbar. Never did slow down or lock up. Had various windows running the script and other sites, etc, instead of running it in a tab this time, why I could use the scrollbar, watch the usage %age, and keep track of the script.

*shrug* No idea. Thing is, I really seldom have the "issues" others have with my machines.... excepting the laptop, which shouldn't have issues being it's brand new - but I'm blaming that on it being born with XPHome instead of a real OS....
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hmm. Scratches head, looks up at the ceiling, sighs. Ok, that's really weird. That was supposed to be my test case for Firefox being problematic. At least you're getting the same processor spikes, that's good, that's a big problem in terms of code efficiency [not of my script, that was designed to work at the limits of what would work in 2000] for Firefox, the other browsers don't even register any processor use.

But it not bogging down, that one I'll have to look into.

By the way, post any weirdnesses, or fondnesses, you find on your laptop in your emachines 5405 review, your emachines stuff is still the number one search topic this week ;-), so there's a lot of people looking at that machine and wanting feedback on it.
Back to top
vkaryl
Status: Contributor
Joined: 31 Oct 2004
Posts: 273
Location: back of beyond - s. UT, closer to Vegas than SLC
Reply Quote
I'll do that on the laptop thread.... though it's not "issues" as such, just that XPHome won't do some stuff I'm used to with Pro, and does some other idiocies I'm not real happy about. So that pretty much belongs in the OS section probably....

Don't know what to suggest far as "bogging down" or the lack thereof on my setup. You know what DOES lock up my box? NWN HotU toward the end of the game, when it wants you to fight/kill 80+ devil warriors spawned by light beams.... *sigh*
Back to top
Display posts from previous:   
Page: 1, 2  Next
All times are GMT - 8 Hours