Feb 28

Quick: How long does it take to construct one million C# objects?

1/4 second.

In the “old days,” a major knock against object-oriented programming (such as with C++) was the perceived overhead required to create and maintain objects in memory.  My how times have changed!

Given a simple three-property object as shown below:

class Person
{
    public string Name;
    public string Address;
    public DateTime Birthdate;
}

Amazingly, it takes an average of 0.25 seconds to create 1 million Person objects.  Of course times vary widely by PC, and most objects are much more complex and have initializers, but this simple test demonstrates how fast computers have become.

For all you youngins out there, this story is equivalent to your grandparents walking to school uphill both ways.  You can roll your eyes now.

Share and Enjoy:
  • Twitter
  • Facebook
  • Reddit
  • LinkedIn
  • Digg
  • DotNetKicks
  • StumbleUpon
  • Slashdot
  • Technorati
  • Google Bookmarks
  • Print
  • email

Article published on February 28, 2008




3 Responses to “One Million Objects”

  1. Daily Find #37 | TechToolBlog Says:

    […] One Million Objects in c# – How long do you thing it takes? Answer before clicking. […]

  2. One Million Objects « the REAL NEWS for you and me. Says:

    […] One Million Objects 29 01 2009 One Million Objects […]

  3. Max Says:

    I remember the good ol’ days when we had to use unions in C to save memory by sharing the same space for multiple properties!

Leave a Reply