[Mono-list] offtopic, but cool
Cory Nelson
phrosty@gmail.com
Wed, 12 May 2004 04:56:32 -0700
------=_Part_0_14005963.1084362992637
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
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).
------=_Part_0_14005963.1084362992637
Content-Type: text/plain; name="test.cs"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="test.cs"
#region Using directives
using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
#endregion
namespace SpeedTest {
=09class Program {
=09=09static void Main(string[] args) {
=09=09=09ArrayList al =3D new ArrayList();
=09=09=09List<Rectangle> rl =3D new List<Rectangle>();
=09=09=09DateTime start, end;
=09=09=09GC.Collect();
=09=09=09GC.WaitForPendingFinalizers();
=09=09=09start =3D DateTime.Now;
=09=09=09for (int i =3D 0; i < 1000000; i++)
=09=09=09=09al.Add(new Rectangle(i, i, i, i));
=09=09=09end =3D DateTime.Now;
=09=09=09Console.WriteLine("Arraylist: {0:F3}ms", (end-start).TotalMi=
lliseconds);
=09=09=09GC.Collect();
=09=09=09GC.WaitForPendingFinalizers();
=09=09=09start =3D DateTime.Now;
=09=09=09for (int i =3D 0; i < 1000000; i++)
=09=09=09=09rl.Add(new Rectangle(i, i, i, i));
=09=09=09end =3D DateTime.Now;
=09=09=09Console.WriteLine("List<Rectangle>: {0:F3}ms", (end - start).Tota=
lMilliseconds);
=09=09}
=09}
}
------=_Part_0_14005963.1084362992637
Content-Type: text/plain; name="test.cpp"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment; filename="test.cpp"
#include <list>
#include <iostream>
#include <ctime>
using namespace std;
struct rect {
=09int x;
=09int y;
=09int width;
=09int height;
};
int main(void) {
=09list<rect> rl;
=09clock_t start=3Dclock();
=09for(int i=3D0; i<1000000; i++) {
=09=09rect r=3D{i, i, i, i};
=09=09rl.push_back(r);
=09}
=09clock_t end=3Dclock();
=09cout << "list<rect>: " << (((float)(end-start))/((float)CLOCKS_PER_SEC)*=
1000.0f) << "ms" << endl;
=09return 0;
}
------=_Part_0_14005963.1084362992637--