out method and method with return value

  • Thread starter Thread starter lianqtlit
  • Start date Start date
L

lianqtlit

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?
 
lianqtlit said:
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.
 
lianqtlit said:
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
 
Michael said:
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
 
Arne Vajhøj said:
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
 
lianqtlit said:
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.
 
Willy Denoyette said:
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).
 
Ben Voigt said:
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.
 
Willy Denoyette said:
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
 
Michael C said:
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.
 
Willy Denoyette said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top