How expensive are method calls in .net
.net
Solution
That will depend on many things
- Whether the JIT inlines it for you
- Whether it's virtual
- The number and size of parameters
- Whether it's an instance method (with the implicit nullity check)
- Whether there's a return value (and its size if so)
It's very, very unlikely to be your bottleneck though. As always, write the most readable code you can first, and then benchmark it to see whether it performs well enough. If it doesn't, use a profiler to find the hotspots which may be worth micro-optimising.
Problem
What is the relative performance cost of calling a method over in-line code?