The only difference is the ArrayList requires boxing to Object. ArrayList: L_002a: newobj instance void [System.Drawing]System.Drawing.Rectangle::.ctor(int32, int32, int32, int32) L_002f: box [System.Drawing]System.Drawing.Rectangle L_0034: callvirt instance int32 [mscorlib]System.Collections.ArrayList::Add(object)
List<Rectangle>: L_008c: newobj instance void [System.Drawing]System.Drawing.Rectangle::.ctor(int32, int32, int32, int32) L_0091: callvirt instance int32 [mscorlib]System.Collections.Generic.List!1<[System.Drawing]System.Drawing.Rectangle>::Add(!0) On Wed, 12 May 2004 10:18:57 -0400, Dan <[EMAIL PROTECTED]> wrote: > > Cory, I'm curious, did you compare the IL to see whats different? > > -Dan > > > -----Original Message----- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Lluis Sanchez > Sent: Wednesday, May 12, 2004 9:17 AM > To: Cesar Mello > Cc: Cory Nelson; mono-list > Subject: Re: [Mono-list] offtopic, but cool > > System.Drawing.Rectangle is a struct, so it is copied by value, not by > reference. > > On dc, 2004-05-12 at 14:41, Cesar Mello wrote: > > Hi Cory, > > > > In the C++ sample, you are passing the rect by value, so you are > > saving a copy in the list. In C# a reference to the object is used, so > > there is no copy-construction overhead. > > > > You can change the list<rect> to a list<rect*>, but this way you have > > to manage the memory by yourlself. > > > > [] > > Mello > > > > > > > > Cory Nelson wrote: > > > Just got done installing the VS.NET 2005 preview and did a small test. > > > > > > I compared an ArrayList of Rectangles to a List<Rectangle>, and > > > timed inserting 1mil rects into each. I also wrote an equivalent c++ > app. > > > Got some interesting results: > > > > > > ArrayList: 265ms > > > List<Rectangle>: 62ms > > > list<rect>: 141ms > > > > > > So it seems with generics .NET is finally faster than c++ (at least, > > > in this case). > > > > > > Esta mensagem foi verificada pelo E-mail Protegido Terra. > > > Scan engine: VirusScan / Atualizado em 10/05/2004 / Versão: 1.5.2 > > > Proteja o seu e-mail Terra: http://www.emailprotegido.terra.com.br/ > > > > > > > > > ____________________________________________________________________ > > > #region Using directives > > > > > > using System; > > > using System.Collections; > > > using System.Collections.Generic; > > > using System.Drawing; > > > > > > #endregion > > > > > > namespace SpeedTest { > > > class Program { > > > static void Main(string[] args) { > > > ArrayList al = new ArrayList(); > > > List<Rectangle> rl = new List<Rectangle>(); > > > DateTime start, end; > > > > > > GC.Collect(); > > > GC.WaitForPendingFinalizers(); > > > > > > start = DateTime.Now; > > > for (int i = 0; i < 1000000; i++) > > > al.Add(new Rectangle(i, i, i, i)); > > > end = DateTime.Now; > > > > > > Console.WriteLine("Arraylist: {0:F3}ms", > (end-start).TotalMilliseconds); > > > > > > GC.Collect(); > > > GC.WaitForPendingFinalizers(); > > > > > > start = DateTime.Now; > > > for (int i = 0; i < 1000000; i++) > > > rl.Add(new Rectangle(i, i, i, i)); > > > end = DateTime.Now; > > > > > > Console.WriteLine("List<Rectangle>: {0:F3}ms", (end > - start).TotalMilliseconds); > > > } > > > } > > > } > > > > > > > > > > > > ____________________________________________________________________ > > > #include <list> > > > #include <iostream> > > > #include <ctime> > > > using namespace std; > > > > > > struct rect { > > > int x; > > > int y; > > > int width; > > > int height; > > > }; > > > > > > int main(void) { > > > list<rect> rl; > > > > > > clock_t start=clock(); > > > for(int i=0; i<1000000; i++) { > > > rect r={i, i, i, i}; > > > rl.push_back(r); > > > } > > > clock_t end=clock(); > > > > > > cout << "list<rect>: " << > > > (((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f) << "ms" << > > > endl; > > > > > > return 0; > > > } > > > > > > > > > > _______________________________________________ > Mono-list maillist - [EMAIL PROTECTED] > http://lists.ximian.com/mailman/listinfo/mono-list > > _______________________________________________ Mono-list maillist - [EMAIL PROTECTED] http://lists.ximian.com/mailman/listinfo/mono-list