Abstact class vs interface speed

  • Thread starter Thread starter almurph
  • Start date Start date
A

almurph

Hi,

I heard that an abstract class is faster than an interface. Why?

I would appreciate your comments/subbestions/replies on this.

Thank you,
Al.
 
I heard that an abstract class is faster than an interface. Why?

"Why" what? Why have you heard that? Or why is it faster?

I can't answer the former, and the latter isn't really true. The only
members worth comparing between an abstract class and an interface are
those that would in fact appear in the interface, and those will have the
same performance characteristics whether they appear in an abstract class
or an interface (they'd be virtual members in either case).

If you have a specific reference to a statement you have a question about,
a more specific answer might be provided. But as your question stands
now, there's no way to answer "why", to whatever question it is you're
asking.

Pete
 
I heard that an abstract class is faster than an interface. Why?

I can not see why that should be the case. But that does not preclude
it from being so. If you really want to know, then you can study
the generated MSIL code and if they are different measure it.

But why are you wasting your valuable time on something like this?

Even if there is a difference it will not be measurable for a real
application.

And it is not given by the specification and could change with
any new version of the CLR.

Arne
 
I remember reading about that too a while ago, I can't remember really where, it
could have been off a webpage from Microsoft. Here it is stated in CodeProject by
someone; http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx.

Speed:

Interface: Requires more time to find the method in the corresponding Class.
Abstract: Fast.

Al when I first read this a while ago I took it for face value as I wouldn't know
how to challenge it. After reading Peter's and Arne's responses, maybe the quote
above from the CodeProject website is also saying Interface: Fast...???? Of course
how much (more) time???


--
NJC©(TM)

| Hi,
|
| I heard that an abstract class is faster than an interface. Why?
|
| I would appreciate your comments/subbestions/replies on this.
|
| Thank you,
| Al.
 
I remember reading about that too a while ago, I can't remember really
where, it
could have been off a webpage from Microsoft. Here it is stated in
CodeProject by
someone; http://www.codeproject.com/KB/cs/abstractsvsinterfaces.aspx.

Speed:

Interface: Requires more time to find the method in the corresponding
Class.
Abstract: Fast.

Al when I first read this a while ago I took it for face value as I
wouldn't know
how to challenge it. After reading Peter's and Arne's responses, maybe
the quote
above from the CodeProject website is also saying Interface: Fast...????
Of course
how much (more) time???

I really have no idea what the author is trying to state there.
Unfortunately, while the article has a number of very good, useful points,
those are undermined by imprecision and vagueness in other parts of the
discussion.

I find myself wondering if by "Speed", the author is describing code
maintenance, though even there the idea that it's harder to find the
implementation of an interface in a class than to find the implementation
of abstract members doesn't really make any sense either.

In terms of performance, the very first comment to the article does a fine
job debunking any claims of speed differential. The commenter does point
out that accessing fields is faster in abstract classes, but only because
interfaces can't have fields; in an interface, access to a field always
has to go through a virtual property, which can't be inlined and suffers
the infinitessimal overhead of a virtual method call (a non-virtual
property with a trivial getter could be inlined, and would most likely
perform as well as a field...but again, interfaces can't have non-virtual
properties).

Basically, it's simply not true that an abstract class is faster, in the
sense of execution performance, than an interface. It's probably not
faster in any other sense either. :)

Pete
 
Hi, please read MSDN help documents, its
URL:ms-help://MS.MSDNQTR.v80.chs/MS.MSDN.v80/MS.NETDEVFX.v20.chs/dv_fxdesignguide/html/c486dd99-2fcf-454b-b076-8fc7cbf7df9b.htm
 
Back
Top