Re: [Mono-list] offtopic, but cool

2004-05-13 Thread Jonathan Pryor
It just occurred to me, but this test is really unfair to C++. 
std::list is a linked-list, requiring a heap allocation for each node in
the list.  ArrayList and ListT both use arrays for their internal
storage, and thus would require far fewer allocations.

I would suggest re-testing the C++ program, but use std::vector instead
of std::list.  std::vector is the array-based implementation, which is
supposed to provide (amortized) O(1) append time.  (Of course, std::list
also provides O(1) append and insert time, but the heap allocation per
node requirement is a killer, as opposed to the probable log(n) heap
allocations an array would require, assuming you don't pre-allocate the
array.)

Which reminds me: running the test with the List/vector pre-allocated
would be interesting, as it would help to remove the C++ heap allocator
and the GC from the performance equation, allowing us to see a better
comparison between the two models.

 - Jon

On Wed, 2004-05-12 at 07:56, 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 ListRectangle, and timed
 inserting 1mil rects into each.  I also wrote an equivalent c++ app. 
 Got some interesting results:
 
 ArrayList: 265ms
 ListRectangle: 62ms
 listrect: 141ms
 
 So it seems with generics .NET is finally faster than c++ (at least,
 in this case).

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] offtopic, but cool

2004-05-13 Thread Cory Nelson
Good point.  I re-coded with that in mind, and it seems as long as you
preallocate the c++ vector, it wins:

vectorrect: 109ms
vectorrect(100): 15ms

ListRectangle: 78.13ms
ListRectangle(100): 46.88ms

Perhaps std::vectorT is allocating smaller chunks than ListT?


On Thu, 13 May 2004 06:54:41 -0400, Jonathan Pryor [EMAIL PROTECTED] wrote:
 
 It just occurred to me, but this test is really unfair to C++.
 std::list is a linked-list, requiring a heap allocation for each node in
 the list.  ArrayList and ListT both use arrays for their internal
 storage, and thus would require far fewer allocations.
 
 I would suggest re-testing the C++ program, but use std::vector instead
 of std::list.  std::vector is the array-based implementation, which is
 supposed to provide (amortized) O(1) append time.  (Of course, std::list
 also provides O(1) append and insert time, but the heap allocation per
 node requirement is a killer, as opposed to the probable log(n) heap
 allocations an array would require, assuming you don't pre-allocate the
 array.)
 
 Which reminds me: running the test with the List/vector pre-allocated
 would be interesting, as it would help to remove the C++ heap allocator
 and the GC from the performance equation, allowing us to see a better
 comparison between the two models.
 
 - Jon
 
 
 On Wed, 2004-05-12 at 07:56, 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 ListRectangle, and timed
  inserting 1mil rects into each.  I also wrote an equivalent c++ app.
  Got some interesting results:
 
  ArrayList: 265ms
  ListRectangle: 62ms
  listrect: 141ms
 
  So it seems with generics .NET is finally faster than c++ (at least,
  in this case).
 

#region Using directives

using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;

#endregion

namespace SpeedTestNet {
class Program {
static void testlist() {
GC.Collect();
GC.WaitForPendingFinalizers();

ListRectangle rl=new ListRectangle();
DateTime start, end;

start=DateTime.Now;
for(int i=0; i100; i++)
rl.Add(new Rectangle(i, i, i, i));
end=DateTime.Now;

Console.WriteLine(ListRectangle:  {0:F2}ms, 
(end-start).TotalMilliseconds);
rl.Clear();
}

static void testlistpa() {
GC.Collect();
GC.WaitForPendingFinalizers();

ListRectangle rl=new ListRectangle(100);
DateTime start, end;

start=DateTime.Now;
for(int i=0; i100; i++)
rl.Add(new Rectangle(i, i, i, i));
end=DateTime.Now;

Console.WriteLine(ListRectangle(100): {0:F2}ms, 
(end-start).TotalMilliseconds);
rl.Clear();
}

static void Main(string[] args) {
testlist();
testlistpa();
}
}
}
#include vector
#include iostream
#include ctime
using namespace std;

struct rect {
int x;
int y;
int width;
int height;
};

static void testvector(void) {
vectorrect rv;
clock_t start, end;

start=clock();
for(int i=0; i100; i++) {
rect r={i, i, i, i};
rv.push_back(r);
}
end=clock();

cout  vectorrect:
(((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f)  ms  endl;
}

static void testvectorpa(void) {
vectorrect rv(100);
clock_t start, end;

start=clock();
for(int i=0; i100; i++) {
rect r={i, i, i, i};
rv[i]=r;
}
end=clock();

cout  vectorrect(100):   
(((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f)  ms  endl;
}

int main(void) {
testvector();
testvectorpa();

return 0;
}


[Mono-list] offtopic, but cool

2004-05-12 Thread Cory Nelson
Just got done installing the VS.NET 2005 preview and did a small test.

I compared an ArrayList of Rectangles to a ListRectangle, and timed
inserting 1mil rects into each.  I also wrote an equivalent c++ app. 
Got some interesting results:

ArrayList: 265ms
ListRectangle: 62ms
listrect: 141ms

So it seems with generics .NET is finally faster than c++ (at least,
in this case).
#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();
ListRectangle rl = new ListRectangle();
DateTime start, end;

GC.Collect();
GC.WaitForPendingFinalizers();

start = DateTime.Now;
for (int i = 0; i  100; 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  100; i++)
rl.Add(new Rectangle(i, i, i, i));
end = DateTime.Now;

Console.WriteLine(ListRectangle:  {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) {
listrect rl;

clock_t start=clock();
for(int i=0; i100; i++) {
rect r={i, i, i, i};
rl.push_back(r);
}
clock_t end=clock();

cout  listrect:   
(((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f)  ms  endl;

return 0;
}


Re: [Mono-list] offtopic, but cool

2004-05-12 Thread Cesar Mello




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 listrect to a listrect*, 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 ListRectangle, and timed
inserting 1mil rects into each.  I also wrote an equivalent c++ app. 
Got some interesting results:

ArrayList: 265ms
ListRectangle: 62ms
listrect: 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 / Verso: 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();
			ListRectangle rl = new ListRectangle();
			DateTime start, end;

			GC.Collect();
			GC.WaitForPendingFinalizers();

			start = DateTime.Now;
			for (int i = 0; i  100; 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  100; i++)
rl.Add(new Rectangle(i, i, i, i));
			end = DateTime.Now;

			Console.WriteLine("ListRectangle:  {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) {
	listrect rl;

	clock_t start=clock();
	for(int i=0; i100; i++) {
		rect r={i, i, i, i};
		rl.push_back(r);
	}
	clock_t end=clock();

	cout  "listrect: "  (((float)(end-start))/((float)CLOCKS_PER_SEC)*1000.0f)  "ms"  endl;

	return 0;
}

  






Re: [Mono-list] offtopic, but cool

2004-05-12 Thread Cory Nelson
Yea I thought of that, but doing so made it take twice the time:

listrect* rl;
for(int i=0; i100; i++) {
rect *r=new rect;
r-x=i;
r-y=i;
r-width=i;
r-height=i;

rl.push_back(r);
}


- Original Message -
From: Cesar Mello [EMAIL PROTECTED]
Date: Wed, 12 May 2004 09:41:24 -0300
Subject: Re: [Mono-list] offtopic, but cool
To: Cory Nelson [EMAIL PROTECTED]
Cc: mono-list [EMAIL PROTECTED]


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 listrect to a listrect*, 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 ListRectangle, and timed
inserting 1mil rects into each.  I also wrote an equivalent c++ app. 
Got some interesting results:

ArrayList: 265ms
ListRectangle: 62ms
listrect: 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/
___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


RE: [Mono-list] offtopic, but cool

2004-05-12 Thread Dan
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 listrect to a listrect*, 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 ListRectangle, and 
  timed inserting 1mil rects into each.  I also wrote an equivalent c++
app.
  Got some interesting results:
  
  ArrayList: 265ms
  ListRectangle: 62ms
  listrect: 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();
  ListRectangle rl = new ListRectangle();
  DateTime start, end;
  
  GC.Collect();
  GC.WaitForPendingFinalizers();
  
  start = DateTime.Now;
  for (int i = 0; i  100; 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  100; i++)
  rl.Add(new Rectangle(i, i, i, i));
  end = DateTime.Now;
  
  Console.WriteLine(ListRectangle:  {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) {
  listrect rl;
  
  clock_t start=clock();
  for(int i=0; i100; i++) {
  rect r={i, i, i, i};
  rl.push_back(r);
  }
  clock_t end=clock();
  
  cout  listrect:   
  (((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


Re: [Mono-list] offtopic, but cool

2004-05-12 Thread Cesar Mello
Hi Cory!

yeap you're right! I didn't notice the struct was small. I'd like to see 
the struct you used in the C++ sample if possible (just 4 ints?)

I'll do the same benchmark later when I get home, and try with different 
compilers and allocators. Pretty interesting!

Best regards,
Mello
Cory Nelson wrote:

Yea I thought of that, but doing so made it take twice the time:

listrect* rl;
for(int i=0; i100; i++) {
rect *r=new rect;
r-x=i;
r-y=i;
r-width=i;
r-height=i;
rl.push_back(r);
}
- Original Message -
From: Cesar Mello [EMAIL PROTECTED]
Date: Wed, 12 May 2004 09:41:24 -0300
Subject: Re: [Mono-list] offtopic, but cool
To: Cory Nelson [EMAIL PROTECTED]
Cc: mono-list [EMAIL PROTECTED]
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 listrect to a listrect*, 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 ListRectangle, and timed
inserting 1mil rects into each.  I also wrote an equivalent c++ app. 
Got some interesting results:

ArrayList: 265ms
ListRectangle: 62ms
listrect: 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/
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/


 

___
Mono-list maillist  -  [EMAIL PROTECTED]
http://lists.ximian.com/mailman/listinfo/mono-list


Re: [Mono-list] offtopic, but cool

2004-05-12 Thread Cory Nelson
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)

ListRectangle:
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 listrect to a listrect*, 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 ListRectangle, and
   timed inserting 1mil rects into each.  I also wrote an equivalent c++
 app.
   Got some interesting results:
  
   ArrayList: 265ms
   ListRectangle: 62ms
   listrect: 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();
   ListRectangle rl = new ListRectangle();
   DateTime start, end;
  
   GC.Collect();
   GC.WaitForPendingFinalizers();
  
   start = DateTime.Now;
   for (int i = 0; i  100; 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  100; i++)
   rl.Add(new Rectangle(i, i, i, i));
   end = DateTime.Now;
  
   Console.WriteLine(ListRectangle:  {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) {
   listrect rl;
  
   clock_t start=clock();
   for(int i=0; i100; i++) {
   rect r={i, i, i, i};
   rl.push_back(r);
   }
   clock_t end=clock();
  
   cout  listrect:  
   (((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