> these arrays grow themselves exponentially
Are you sure about this? Where did you get this information?

As far as I can tell by looking at mscorlib.dll using dis-compiler,
ArrayList.Add() uses:
        if (this._size == (int) this._items.Length)
                this.EnsureCapacity(this._size + 1);

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]] On Behalf Of Ian Griffiths
Sent: Sunday, July 07, 2002 3:22 AM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] Specifying an initial capacity hurts
performance [was Benchmark]


"David Ferguson" <[EMAIL PROTECTED]> wrote:
>
> Certainly in this test (large array, constant value) it
> does appear to be slower (not significantly, but a little).
>
>     >By value, dynamically reallocated | >By value, preallocated
>                                        | (with pause between test)
>     >----Test 0                        | >----Test 0
>     >Elapsed 640 ms                    | >Elapsed 661 ms
>     >----Test 1                        | >----Test 1
>     >Elapsed 590 ms                    | >Elapsed 651 ms
>     >----Test 2                        | >----Test 2
>     >Elapsed 691 ms                    | >Elapsed 651 ms
>     >----Test 3                        | >----Test 3
>     >Elapsed 621 ms                    | >Elapsed 651 ms
>     >----Test 4                        | >----Test 4
>     >Elapsed 601 ms                    | >Elapsed 651 ms
>   ----------------------             ------------------------------
>     average 629                          average 653

But the variance is pretty huge on your first column there.  I think the
different of 24ms is swamped by the uncertainty in the measurements.

So with your data I came to the same conclusion as I did with my data:
it's difficult to tell which, if either, is faster, without more
extensive measurement and careful analysis.

This is what you would expect - the difference in allocation count for
preallocation will only amount to a fairly small number (these arrays
grow themselves exponentially, so the number of allocations is small).
So you'd expect it to be too small to measure easily.


--
Ian Griffiths
DevelopMentor

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or subscribe to other DevelopMentor lists at
http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to