Passing by ref in C# - why is it slower?
simon.carter
Posts: 8
Please redirect me if this is the wrong place for this kind of post as this isn't really an ANTS issue, just something we've found by using ANTS.
I'm finding that passing some objects, especially smaller ones, by reference is up to 20% slower than making a copy. Sometimes passing by ref is up to 20% faster. I'd assumed from my c++ background that this would normally be true. What's going on? Is there any way to predict when using ref will be faster? Looking at the disassembly isn't necessarily that helpful as it doesn't explain why the code has been compiled that way.
I'm finding that passing some objects, especially smaller ones, by reference is up to 20% slower than making a copy. Sometimes passing by ref is up to 20% faster. I'd assumed from my c++ background that this would normally be true. What's going on? Is there any way to predict when using ref will be faster? Looking at the disassembly isn't necessarily that helpful as it doesn't explain why the code has been compiled that way.
Comments
Could you post some sample code to show what you're doing?
Mel
MyMethodByRef is often slower.
Mel
The main thing is that ANTS gives me the results I need, so cheers.
Simon