One of my colleagues told me that implementing interfaces introduces overhead. Is this true?
I am not concerned about micro optimizations; I just want to know the deeper details this entails.
See Question&Answers more detail:osOne of my colleagues told me that implementing interfaces introduces overhead. Is this true?
I am not concerned about micro optimizations; I just want to know the deeper details this entails.
See Question&Answers more detail:oscouldn't resist and tested it and it looks like almost no overhead.
Participants are:
Interface IFoo defining a method
class Foo: IFoo implements IFoo
class Bar implements the same method as Foo, but no interface involved
so i defined
Foo realfoo = new Foo();
IFoo ifoo = new Foo();
Bar bar = new Bar();
and called the method, which does 20 string concatenations, 10,000,000 times on each variable.
realfoo: 723 Milliseconds
ifoo: 732 Milliseconds
bar: 728 Milliseconds
If the method does nothing, the actual calls stand out a bit more.
realfoo: 48 Milliseconds
ifoo: 62 Milliseconds
bar: 49 Milliseconds