Re: many Array creations are slowing down
From: David Wang [Msft] (someone_at_online.microsoft.com)
Date: 02/22/04
- Next message: Martin Honnen: "Re: Where can i download the complete DHTML and JScript reference"
- Previous message: David Wang [Msft]: "Re: listing all matches - JSCRIPT under WSH REGEX - NEWBIE"
- In reply to: Alexander LAW: "many Array creations are slowing down"
- Next in thread: Alexander LAW: "Re: many Array creations are slowing down"
- Reply: Alexander LAW: "Re: many Array creations are slowing down"
- Messages sorted by: [ date ] [ thread ]
Date: Sun, 22 Feb 2004 00:50:57 -0800
What is killing performance in this case is NOT Array creation but rather
the a.push() command.
- If you remove the a.push(cp); instruction, you should see relatively
steady execution timing.
- If you change it to a.push(1); instruction, you see steadily increasing
timing
- If you change it to a[i] = 1; instruction, you see relatively steady
execution timing
- If you change it to a[i] = cp; instruction, you see relatively steady
execution timing
This suggests that a.push() of dynamic objects isn't performant (not that
hard to believe). If you are truly performance conscious, I would suggest
you:
1. Preallocate the Array's size and avoid the costs of "growing" the array
during execution, which would randomize performance
2. Directly index into the array to avoid other unnecessary calculations
Honestly, asking why Mozilla/Netscape/Opera allows a certain snippet of
unperformant code to execute faster than something else is not really
meaningful because I can just say "it's featuritis" and point you at another
snippet that Mozilla/Netscape/Opera will execute slower. The way to have
consistent performance is to write performant code, which then allows one to
legitimately ask why it's slower in particular implementations.
--
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alexander LAW" <test@mail.ru> wrote in message
news:%23o2fvfE%23DHA.3496@TK2MSFTNGP10.phx.gbl...
Hello, can anyone tell me why creation of Array is slowing down?
Why second thousand of "new Array()" executes slower than the first one?
Here is the small test:
<HTML>
<BODY>
<SCRIPT>
var a=new Array(), dt1, dt2, dtcnt, s="";
for (var j=0;j<10;j++) {
dt2=0; dtcnt=0;
for (var i=0;i<10000;i++) {
dt1=(new Date()).valueOf();
cp=new Array();
dt2=dt2+((new Date()).valueOf()-dt1); dtcnt++;
a.push(cp);
}
s=s+j+": "+dt2/1000+"\n";
}
alert(s);
</SCRIPT>
On Athlon-1200 I get:
0: 0.421
1: 1.122
2: 1.732
3: 2.384
4: 3.046
5: 3.617
6: 4.274
7: 4.858
8: 5.518
9: 6.151
Mozilla, Netscape, Opera are executing this much faster.
Mozilla, for example:
0: 0.2
1: 0.21
2: 0.211
3: 0.13
4: 0.16
5: 0.18
6: 0.2
7: 0.201
8: 0.16
9: 0.2
I think, there is some oddity in scripting host core...
Maybe someone knows workarounds of this?
Thanks in advance.
WBR,
Alexander
</BODY>
</HTML>
- Next message: Martin Honnen: "Re: Where can i download the complete DHTML and JScript reference"
- Previous message: David Wang [Msft]: "Re: listing all matches - JSCRIPT under WSH REGEX - NEWBIE"
- In reply to: Alexander LAW: "many Array creations are slowing down"
- Next in thread: Alexander LAW: "Re: many Array creations are slowing down"
- Reply: Alexander LAW: "Re: many Array creations are slowing down"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|