467,893 Members | 1,913 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,893 developers. It's quick & easy.

Method vs Property performance

Hi,

Since small method calls are inlined when the IL size is 32 or less.

Take for example..

// Method (inlined)
public bool getVal()
{
return someVal;
}

// propget
public bool Val
{
ge { return someVal; }
}
Which is faster? If the method is unoptimised its therefore poped onto
the stack so obviously slower than the propget.

When it is inline its not pushed onto the stack, but it is JITted to be
inline wheras a prop is what?

Is there a difference or is it smart enough? Does the method take ahit on
the initial JIT and the propget doesnt?

Thanks
Nov 15 '05 #1
  • viewed: 4599
Share:
2 Replies
I would think it is smart enough. The reason being is that properties
are really methods (you will notice get_Property and set_Property methods on
your class when you look at the IL), and I would imagine that these are
subject to the same optimizations.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<di********@discussion.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

Since small method calls are inlined when the IL size is 32 or less.

Take for example..

// Method (inlined)
public bool getVal()
{
return someVal;
}

// propget
public bool Val
{
ge { return someVal; }
}
Which is faster? If the method is unoptimised its therefore poped onto
the stack so obviously slower than the propget.

When it is inline its not pushed onto the stack, but it is JITted to be
inline wheras a prop is what?

Is there a difference or is it smart enough? Does the method take ahit on the initial JIT and the propget doesnt?

Thanks

Nov 15 '05 #2
That's my guess as well.

Why not just write a simple test program? Either run and time it, or look
at the IL and see if there are any differences.

Remember though, the optimizations that the compiler does will change
(hopefully improve) with each release.

Eric

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:e3**************@TK2MSFTNGP11.phx.gbl...
I would think it is smart enough. The reason being is that properties
are really methods (you will notice get_Property and set_Property methods on your class when you look at the IL), and I would imagine that these are
subject to the same optimizations.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<di********@discussion.microsoft.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,

Since small method calls are inlined when the IL size is 32 or less.

Take for example..

// Method (inlined)
public bool getVal()
{
return someVal;
}

// propget
public bool Val
{
ge { return someVal; }
}
Which is faster? If the method is unoptimised its therefore poped onto the stack so obviously slower than the propget.

When it is inline its not pushed onto the stack, but it is JITted to be inline wheras a prop is what?

Is there a difference or is it smart enough? Does the method take ahit

on
the initial JIT and the propget doesnt?

Thanks



Nov 15 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by fred | last post: by
4 posts views Thread by kplkumar | last post: by
19 posts views Thread by zzw8206262001 | last post: by
15 posts views Thread by caca | last post: by
7 posts views Thread by Brian | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.