Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

C# properties, what is the performance hit?

Status
Not open for further replies.

CNTower

Programmer
Nov 17, 2006
3
CA
Hi,

I remember reading how the sample application by microsoft was (Pet Store I think it was called) is much faster that the same application but written in java.

I believe the MS version didn't use properties. This webpage talks about C# properties:
Does anyone have any performance numbers as to how much slower an application becomes?
 
The compiler is optimized for the use of properties in .Net

Age is a consequence of experience
 
An experiment you can try is to create a small app that uses both properties and direct field access. You can then inspect the compiled (release configuration!) assembly with a tool like ildasm (ships with .net) or Reflector (available online) to look at the MSIL statements that got created by the compiler. My guess is that there would be little or no difference between them.

If there were differences, the runtime JIT compiler would probably remove them. To examine the output of the JIT is difficult, but you can get close by running the NGEN utility (ships with .net), and examining the x86 instructions that it produces.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Suggest you only worry about potential performance issues if you actually have them. Unless you are serving hundreds of web requests a second, you are better off writing code that is easier to understand and maintain rather than jumping through coding hoops to address a problem that *might* occur sometime in the future.

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top