Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Performance / May 2007

Tip: Looking for answers? Try searching our database.

c# static constructor?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ms news group - 03 May 2007 04:45 GMT
I have done some research on this issue, but still quite puzzled.
I read one article that says static constructor can be a big performance
hit, it even gives some code fragment, which, accoring to that article,
could show a big difference betweeen using static constructor or not. But
when I run his code, I found no significant diifference at all.
For this reason, I even checked the assemly code of using static
constructor, and I can not find any thing that will cause performornce
degradation.
Or course, lazy initialization is good, but not all cases really care that
much about startup time, so I doubt if the performance issue of static
constructor is exagerated.

Could someone shed some light on this?
Jon Skeet [C# MVP] - 03 May 2007 19:55 GMT
> I have done some research on this issue, but still quite puzzled.
> I read one article that says static constructor can be a big performance
[quoted text clipped - 9 lines]
>
> Could someone shed some light on this?

For classes with static constructors, the type initializer can't be
executed until the first time a member of the class is *actually*
referenced, rather than just at (say) the start of a method where a
member of the class *might* be referenced.

I wouldn't say it's a particularly significant performance hit even in
the most extreme situations I've looked at, but it *is* noticeable if
you have (say) a very tight loop which just calls a cheap static method
on a class with a static constructor.

Of course, this may have been optimised a bit in .NET 2.0...

Signature

Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet   Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.