467,893 Members | 1,894 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.

out method and method with return value

In performance wise which is more costly to use when there one value to return?
Is it the out method parameter or the method that has a return value?

Dec 19 '07 #1
  • viewed: 1171
Share:
10 Replies
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?
Return value I presume. In most languages the return value is returned in a
register whereas a parameter is placed on the stack.
>

Dec 19 '07 #2
lianqtlit wrote:
In performance wise which is more costly to use when there one value to return?
Is it the out method parameter or the method that has a return value?
It is extremely unlikely that the difference will have any impact on
your overall performance.

Focus on readable code instead of "nanoseconds performance tuning".

Arne
Dec 19 '07 #3
Michael C wrote:
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?

Return value I presume. In most languages the return value is returned in a
register whereas a parameter is placed on the stack.
Did you read it as "more efficient" or do you think register is slower
than stack ?

Arne
Dec 19 '07 #4
"Arne VajhÝj" <ar**@vajhoej.dkwrote in message
news:47***********************@news.sunsite.dk...
Did you read it as "more efficient" or do you think register is slower
than stack ?
Sorry, I misread what the OP said. I think the register will be faster and
more efficient.

Michael
Dec 19 '07 #5
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?

You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.
Managed code uses the "CLR calling" convention when running on X86, that is,
it passes the first two arguments in a register. The 'this' pointer is
passed in 'ecx' while the "first" argument is passed in 'esi'. More, when
running on X64 in 64-bit mode, the first four arguments are passed in a
register, so here you have even less reasons to care about argument passing
efficiency.

Willy.
Dec 19 '07 #6

"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microsof t.com...
>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?


You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.
out arguments have to be passed by address... unless inlined

Just make sure the function is inlined.

As a side note, the out parameter can use type inference, the return type
can't (except for op_Implicit and op_Explicit).
Dec 19 '07 #7
"Ben Voigt [C++ MVP]" <rb*@nospam.nospamwrote in message
news:uW**************@TK2MSFTNGP04.phx.gbl...
>
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
>"lianqtlit" <li*******@discussions.microsoft.comwrote in message
news:83**********************************@microso ft.com...
>>In performance wise which is more costly to use when there one value to
return?
Is it the out method parameter or the method that has a return value?


You should definitely not care about this, chances are that the method is
inlined, and if not, the (single) argument is passed in a register too.

out arguments have to be passed by address... unless inlined
Yep, sorry for the confusion, what I meant was that a single argument is
passed in a register, not on the stack.
What is returned is also placed in a register (by convention eax on X86), be
it an address or a value
Just make sure the function is inlined.
You don't have control over this, it's the JIT who decides what will be
inlined.
As a side note, the out parameter can use type inference, the return type
can't (except for op_Implicit and op_Explicit).
Agreed.

Willy.


Dec 20 '07 #8
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
You should definitely not care about this, chances are
Chances are much improved (to certainty) that the return value will be in a
register if it is not a parameter. :-)

Michael
Dec 20 '07 #9
"Michael C" <mi**@nospam.comwrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:e3**************@TK2MSFTNGP05.phx.gbl...
>You should definitely not care about this, chances are

Chances are much improved (to certainty) that the return value will be in
a register if it is not a parameter. :-)

Michael
Sure, on X86 return values can even occupy two registers, a long or a double
return value for instance are returned in 'eax' and 'edx'. Note that I'm
absolutely not promoting passing ByRef values, this is a matter of the
semantic requirements, all I'm trying to say is that the JIT32 uses a
calling sequence which allows you to pass single argument (plus the this
pointer) in a register.

Willy.


Dec 20 '07 #10
"Willy Denoyette [MVP]" <wi*************@telenet.bewrote in message
news:ei**************@TK2MSFTNGP06.phx.gbl...
Sure, on X86 return values can even occupy two registers, a long or a
double return value for instance are returned in 'eax' and 'edx'. Note
that I'm absolutely not promoting passing ByRef values, this is a matter
of the semantic requirements, all I'm trying to say is that the JIT32 uses
a calling sequence which allows you to pass single argument (plus the this
pointer) in a register.
Interesting, that's something I didn't know. I still think though that if
you want performance you'd be better off going with the return value because
then you can be pretty much certain it will return in a register. It's
possible in the future your code might not be running on x86.

Michael
Dec 20 '07 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by max reason | last post: by
1 post views Thread by =steFF= | last post: by
3 posts views Thread by BombDrop | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.