[Mono-list] offtopic, but cool

Dan dan@astusa.com
Wed, 12 May 2004 10:18:57 -0400


Cory, I'm curious, did you compare the IL to see whats different?

-Dan=20

-----Original Message-----
From: mono-list-admin@lists.ximian.com
[mailto:mono-list-admin@lists.ximian.com] 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,
>=20
> In the C++ sample, you are passing the rect by value, so you are=20
> saving a copy in the list. In C# a reference to the object is used, so =

> there is no copy-construction overhead.
>=20
> You can change the list<rect> to a list<rect*>, but this way you have=20
> to manage the memory by yourlself.
>=20
> []
> Mello
>=20
>=20
>=20
> Cory Nelson wrote:
> > Just got done installing the VS.NET 2005 preview and did a small =
test.
> >=20
> > I compared an ArrayList of Rectangles to a List<Rectangle>, and=20
> > timed inserting 1mil rects into each.  I also wrote an equivalent =
c++
app.
> > Got some interesting results:
> >=20
> > ArrayList: 265ms
> > List<Rectangle>: 62ms
> > list<rect>: 141ms
> >=20
> > So it seems with generics .NET is finally faster than c++ (at least, =

> > in this case).
> >=20
> > Esta mensagem foi verificada pelo E-mail Protegido Terra.
> > Scan engine: VirusScan / Atualizado em 10/05/2004 / Vers=E3o: 1.5.2=20
> > Proteja o seu e-mail Terra: http://www.emailprotegido.terra.com.br/
> >  =20
> >=20
> > ____________________________________________________________________
> > #region Using directives
> >=20
> > using System;
> > using System.Collections;
> > using System.Collections.Generic;
> > using System.Drawing;
> >=20
> > #endregion
> >=20
> > namespace SpeedTest {
> > 	class Program {
> > 		static void Main(string[] args) {
> > 			ArrayList al =3D new ArrayList();
> > 			List<Rectangle> rl =3D new List<Rectangle>();
> > 			DateTime start, end;
> >=20
> > 			GC.Collect();
> > 			GC.WaitForPendingFinalizers();
> >=20
> > 			start =3D DateTime.Now;
> > 			for (int i =3D 0; i < 1000000; i++)
> > 				al.Add(new Rectangle(i, i, i, i));
> > 			end =3D DateTime.Now;
> >=20
> > 			Console.WriteLine("Arraylist:       {0:F3}ms",
(end-start).TotalMilliseconds);
> >=20
> > 			GC.Collect();
> > 			GC.WaitForPendingFinalizers();
> >=20
> > 			start =3D DateTime.Now;
> > 			for (int i =3D 0; i < 1000000; i++)
> > 				rl.Add(new Rectangle(i, i, i, i));
> > 			end =3D DateTime.Now;
> >=20
> > 			Console.WriteLine("List<Rectangle>:  {0:F3}ms", (end
- start).TotalMilliseconds);
> > 		}
> > 	}
> > }
> >=20
> >  =20
> >=20
> > ____________________________________________________________________
> > #include <list>
> > #include <iostream>
> > #include <ctime>
> > using namespace std;
> >=20
> > struct rect {
> > 	int x;
> > 	int y;
> > 	int width;
> > 	int height;
> > };
> >=20
> > int main(void) {
> > 	list<rect> rl;
> >=20
> > 	clock_t start=3Dclock();
> > 	for(int i=3D0; i<1000000; i++) {
> > 		rect r=3D{i, i, i, i};
> > 		rl.push_back(r);
> > 	}
> > 	clock_t end=3Dclock();
> >=20
> > 	cout << "list<rect>: " <<=20
> > (((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f) << "ms" <<=20
> > endl;
> >=20
> > 	return 0;
> > }
> >=20
> >  =20
>=20

_______________________________________________
Mono-list maillist  -  Mono-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list