473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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
2 4762
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: william | last post by:
Hi, I'm playing windows service using vb.net. I added a performance counter to my windows service, but I couldn't set MachineName property of the performance counter to blank. After I set it to...
5
by: Vicky via DotNetMonster.com | last post by:
Hi, I need help with "An object reference is required for the nonstatic field, method, or property 'dataReader.Class1.data'" Before I put folowing variable in class level, it works fine....
5
by: fred | last post by:
With a Class is there any difference between a readonly property and function besides having to use Get/End Get. Are there any performance/resource advantages for either. Thanks Fred
18
by: JohnR | last post by:
From reading the documentation, this should be a relatively easy thing. I have an arraylist of custom class instances which I want to search with an"indexof" where I'm passing an instance if the...
4
by: kplkumar | last post by:
This is what my supervisor is looking for. We want runtime debugging/trace logging. In other words, we want to log every method that was executed, perhaps the variables in it as well - everytime...
2
by: netasp | last post by:
hi all, I need your help with the following scenario: I am using VS 2005 and SQL server DB, my form has 3 textboxes txtTotalAmount, txtAmountEntered, txtAmountBalance. If txtTotalAmount is...
3
by: jbeteta | last post by:
Hello, I have a problem declaring variables. I need to create an object oRpte as ReportClass on WebForm1.aspx and be able to use its value on WebForm2.aspx. For declaring the property oRpte()...
19
by: zzw8206262001 | last post by:
Hi,I find a way to make javescript more like c++ or pyhon There is the sample code: function Father(self) //every contructor may have "self" argument { self=self?self:this; ...
15
by: caca | last post by:
Hello, This is a question for the best method (in terms of performance only) to choose a random element from a list among those that satisfy a certain property. This is the setting: I need to...
7
by: Brian | last post by:
I am looking for a way to store maybe in an array or dictionary... two fields.... first field would be a string... second would be a date... for example.. if i called up myinfo(0) it would show...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.