Allow operator overloading with "out" for the result #8748
Replies: 2 comments
-
I'd love to see a BenchmarkDotNet table for the extra statistics. |
Beta Was this translation helpful? Give feedback.
-
I made a small benchmark scenario that implements all combinations of static methods and operators with and without aggressive inlining and calls them a couple of times with different inputs. Here's the code: https://gist.github.com/nitroxis/c700ef0f4bbe28cbc3090108410d4034 I used different symbols for the operator overloads but they all do the same (adding two 4x4 matrices). This yields the following results on my machine:
Not sure why calling the static method from within the operator is faster than directly having the code in the operator. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Since it is now possible to pass the parameters for operator overloading as references using the "in" keyword, it would make sense to allow returning the result via an "out" parameter. This has a huge impact on operations on large structs, such as a 4x4 float matrix.
This works right now:
However, this does not:
At the moment, it is still necessary to use static methods with "in, in, out" for maximum performance. I've made a small benchmark that compares the static method variant with the "in" operator overload and found that the static method is still more than 3 times faster than the operator on my machine (i7-6700K).
This is the code that I tested (in Release mode, of course):
Beta Was this translation helpful? Give feedback.
All reactions