Extension methods performance

  • Thread starter Thread starter Luna
  • Start date Start date
L

Luna

are extension methods slower than regular methods?

any performance reduction for using extension methods?
or is it just as fast?

Luna
 
Luna said:
are extension methods slower than regular methods?

any performance reduction for using extension methods?
or is it just as fast?

I have not tested it, but I can not see where the
overhead should come from.

It is a method call. The compiler will need to
figure some things out at compile time but runtime
it is just a method call.

Arne
 
Arne Vajhøj said:
I have not tested it, but I can not see where the
overhead should come from.

It is a method call. The compiler will need to
figure some things out at compile time but runtime
it is just a method call.

And because it is a static method, it could be a little bit faster
sometimes...
 
Luna said:
are extension methods slower than regular methods?

any performance reduction for using extension methods?
or is it just as fast?

Depends on what you mean by a "regular method", if you mean an otherwise
identical static method., I doubt very much that would have any adverse
effects.

However if you are comparing it with adding a new method to the class or
sub-classing that class to add a new method then its worth bearing in mind
that extension methods do not have access to protected or private members of
a class, this may have an impact on performance.
 
Anthony said:
Depends on what you mean by a "regular method", if you mean an
otherwise identical static method., I doubt very much that would have
any adverse effects.

However if you are comparing it with adding a new method to the class
or sub-classing that class to add a new method then its worth bearing
in mind that extension methods do not have access to protected or
private members of a class, this may have an impact on performance.

But because extension methods are never dispatched dynamically, you could
also see a performance improvement. It all depends on how the dynamic
method is implemented.
 
Back
Top