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.
Article published on February 28, 2008
If you like this article, please share it: |
March 3rd, 2008 at 1:34 pm
[…] One Million Objects in c# – How long do you thing it takes? Answer before clicking. […]
January 29th, 2009 at 8:51 pm
[…] One Million Objects 29 01 2009 One Million Objects […]
May 29th, 2009 at 10:18 am
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!