Method vs Property performance

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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 said:
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]
- (e-mail address removed)

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
 
Back
Top