Re: many Array creations are slowing down

Tech-Archive recommends: Speed Up your PC by fixing your registry

From: David Wang [Msft] (someone_at_online.microsoft.com)
Date: 02/24/04


Date: Tue, 24 Feb 2004 10:55:45 -0800

Your script design is flawed in creating many Date() objects and letting
them sit around -- you have no idea whether those extra objects themselves
cause the system to GC, etc. Without an efficient way to store pointers to
the objects being created, I cannot show the counterpoint. And neither case
proves anything about Array creation slowing down, but rather that it can
happen when there are thousands of other objects already in memory. Ok.
Fine.

Regarding storage of method definitions -- yes, they may be functionally
equivalent, but that doesn't mean it's equivalent in performance.

Personally, the notion of "scripting performance" is an oxymoron -- by
design, scripting trades off ease of use and performance because you have
less control over the resultant system. Memory
allocation/deallocation/management/strategy is a part of performance, and
Scripting has no such knobs.

-- 
//David
IIS
This posting is provided "AS IS" with no warranties, and confers no rights.
//
"Alexander LAW" <test@mail.ru> wrote in message
news:%23pjsaSe%23DHA.548@TK2MSFTNGP11.phx.gbl...
Hello, David!
If  you comment out a.push(cp), engine don't store Array in memory and just
frees previous cp value. I'm using "push" intentionally to store all created
objects in memory. You can try to use a[a.length]=cp.  I think you'll see
the same behavior.
I also found that storing methods definition in object definition more
ineffective. For example, object
function tObject() {
  this.method=function() {
  return;
 }
}
creating much more slowly than
function tObject() {
  this.method=tObject_method;
}
function tObject_method {
  return;
 }
Thank you for answer.
With best regards,
    Alexander.
"David Wang [Msft]" <someone@online.microsoft.com>
news:OQWubod#DHA.3488@tk2msftngp13.phx.gbl...
> Hmm, weird.  When I run your code snippet, I see the same dramatic
increase
> in running time per inner loop.  As soon as I commented out  a.push(cp);
,
> I see the runtime per-loop as constant.  This tells me that  a.push(cp)
is
> what is slowing down, not object creation.
>
>    var a=new Array(), dt1, dt2, s="";
>    for (var j=0;j<10;j++) {
>      dt1=(new Date()).valueOf();
>      for (var i=0;i<10000;i++) {
>        cp=new Array();
> //       a[i] = cp;
> //       a.push(cp);
>      }
>      dt2=((new Date()).valueOf()-dt1);
>      s=s+j+": "+dt2/1000+"\n";
>    }
>
> -- 
> //David
> IIS
> This posting is provided "AS IS" with no warranties, and confers no
rights.
> //
> "Alexander LAW" <test@mail.ru> wrote in message
> news:OV90wFU%23DHA.1636@TK2MSFTNGP12.phx.gbl...
> Thank you for support...
> I tried to execute the same code without "Push" command presented in that
> sample. This don't change much strange behavior.
> Yes, push works more slow than just a[], but I dont measure push speed.
See,
> only one string measured...
> > dt1=(new Date()).valueOf();
> >       cp=new Array();
> > dt2=dt2+((new Date()).valueOf()-dt1); dtcnt++;
> Sure, I understand that different people (or teams) make the same thing in
> different ways. I dont pretend to justify one way or another, but just
want
> to understand how to deal with it.
> I dont say that x better than y. I like IE and use other browsers only for
> developing compatible script.
> I can only agree with you about performant code, you surely right.
> I've optimized my code, and start to measure speed of it. I've found
> bottleneck and want to know may I fix it or I need to find some
workaround.
>
> I made one more test and saw the same slowing down while creating String()
> object. So I think question may be redefined as "many Object creations are
> slowing down"...
>
> Have a nice day!


Relevant Pages

  • Re: Problem with ASP on Webserver
    ... No, I know the memory model, I have made my own Virtual memory dump program ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Problem with ASP on Webserver
    ... Entrek's TOOLBOX is a lot better for memory stuff. ... function in the script ... (Accept-Language:) ...
    (microsoft.public.windowsce.platbuilder)
  • Critique my code: using Lisp to parse lots of "ps -elf" files in AIX
    ... It's my first use of Lisp at work, ... and another ksh script to analyze the output. ... success using them to diagnose some of their own memory problems, ... an hour to process about an hour's worth of data (i.e. 60 data files). ...
    (comp.lang.lisp)
  • Re: Incude statement - is there such a thing?
    ... I can't imagine any memory usage issues. ... And it that WSF references ... other script files (as the Docs often suggest to be ... > you had 50 statements that you wanted to execute 1000 times in a loop. ...
    (microsoft.public.scripting.vbscript)
  • Re: Memory Leaks?
    ... > not relinquish all memory back to the available pool for XP to use. ... To flesh this out a bit, memory leaks are a far greater problem in scripts ... When a script terminates, WSH runs a cleanup process that deletes the ... An object will be disconnected only after all references to it ...
    (microsoft.public.windowsxp.general)