Method vs Property performance

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Guest's Avatar

    #1

    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


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Method vs Property performance

    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]
    - mvp@spam.guard. caspershouse.co m

    <discussion@dis cussion.microso ft.com> wrote in message
    news:%23rNg1z2r DHA.3492@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    > 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[/color]
    on[color=blue]
    > the initial JIT and the propget doesnt?
    >
    > Thanks
    >
    >[/color]


    Comment

    • Eric Johannsen

      #3
      Re: Method vs Property performance

      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]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:e3cR262rDH A.3496@TK2MSFTN GP11.phx.gbl...[color=blue]
      > 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[/color]
      on[color=blue]
      > 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]
      > - mvp@spam.guard. caspershouse.co m
      >
      > <discussion@dis cussion.microso ft.com> wrote in message
      > news:%23rNg1z2r DHA.3492@TK2MSF TNGP11.phx.gbl. ..[color=green]
      > > 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[/color][/color]
      onto[color=blue][color=green]
      > > the stack so obviously slower than the propget.
      > >
      > > When it is inline its not pushed onto the stack, but it is JITted to[/color][/color]
      be[color=blue][color=green]
      > > inline wheras a prop is what?
      > >
      > > Is there a difference or is it smart enough? Does the method take ahit[/color]
      > on[color=green]
      > > the initial JIT and the propget doesnt?
      > >
      > > Thanks
      > >
      > >[/color]
      >
      >[/color]

      Comment

      Working...