C# 2.0 Generics and collections

  • Thread starter Thread starter Gary van der Merwe
  • Start date Start date
Anders did some timings on this for his PDC presentation (which we're
working to get up on the C# dev center on MSDN).

IIRC, you save around 10% of the loop overhead in the reference type case
(by avoiding the cast), and something like 50% on the value type case. This
was for essentially empty loops.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
We certainly will not get rid of the existing types, as lots of programs
depend upon them.

We had talked about auto-migration, but it's somewhat unpalatable as we've
taken the opportunity to fix some problems with the ArrayList and Hashtable
classes, but the fixes might break existing code in some rare cases. In the
generics world, you'll use List<T> and Dictionary<K, V> instead.

--
Eric Gunnerson

Visit the C# product team at http://www.csharp.net
Eric's blog is at http://blogs.gotdotnet.com/ericgu/

This posting is provided "AS IS" with no warranties, and confers no rights.
 
I'd love to see his benchmarks. I did mine by adding an item on each
iteration (requiring a box in, or for a reftype, just passing the ref) and
then taking it back out.

The generics version for the reftypes was barely noticable (2**24
iterations, something like 0.02 seconds speed up). Of course, this was
actually doing some real work. I timed the actual cast down to about 3ns
(on a P4c 3GHz), so I'm saving that each time.

For valuetypes, it was a whole different story, the memory requirements got
so high they slowed it down immensely (2**24 objects, since each int was
boxed).

So for "real world" apps, I'd imagine we'll see great (runtime performance)
benefits for valuetypes and an almost unnoticeable improvement for
reftypes...

-mike
MVP
 
Michael,

Mind to share your code? My observations are on par with Anders timings.

Willy.

Michael Giagnocavo said:
I'd love to see his benchmarks. I did mine by adding an item on each
iteration (requiring a box in, or for a reftype, just passing the ref) and
then taking it back out.

The generics version for the reftypes was barely noticable (2**24
iterations, something like 0.02 seconds speed up). Of course, this was
actually doing some real work. I timed the actual cast down to about 3ns
(on a P4c 3GHz), so I'm saving that each time.

For valuetypes, it was a whole different story, the memory requirements got
so high they slowed it down immensely (2**24 objects, since each int was
boxed).

So for "real world" apps, I'd imagine we'll see great (runtime performance)
benefits for valuetypes and an almost unnoticeable improvement for
reftypes...

-mike
MVP
 
Back
Top