Re: Speed of interfaces vs inheritance



Mike Schilling wrote:
"Chris" <spam_me_not@xxxxxxxxxx> wrote in message news:4596b7a9$0$1612$9a6e19ea@xxxxxxxxxxxxxxxxxxxxxxx
In a particularly time-critical part of my app I need to call a method on an external class in a tight loop. The class can be different in different contexts. I've got two choices: create an interface and have the various different classes implement it, or create an abstract class and have the various different classes extend it.

I seem to recall, in years past, that the interface approach was slower. Is this still the case?

(In this particular situation, either approach works fine, though I personally like the interface approach better).

The only way to answer this question is to write a test.

Yeah, but write a good one...

FWIW, a couple years ago I tested dynamically loading a class through a class loader and having a loop repeatedly calling an (interface) method which threw an exception. Under the Sun server HotSpot, the loop was eliminated. Client performance wasn't too bad either.

I believe interface methods can get slow where the same runtime class is called through a number of different interfaces. A highly unlikely situations, particularly if you were considering an abstract base class.

Tom Hawtin
.



Relevant Pages

  • Re: SOLVED: lo0 not in ioctl( SIOCGIFCONF )
    ... bzero(ifr, sizeof(*ifr) * n); ... There are several problems with this loop. ... Yes, your algorithm is O), but allocating a larger ... interface and one per address so you to keep track of the last interface ...
    (freebsd-net)
  • Re: Ada Popularity: Comparison of Ada/Charles with C++ STL (and Perl)
    ... >> Here the iterator type and its constraint are constructed out of the ... for Index in reverse V'First + 4..V'Last loop ... language supports multiple interface inheritance. ...
    (comp.lang.ada)
  • Re: Creating many letters(mail merge) from a single template in C#
    ... I understand that you and users decide to use the interface to insert ... In this case, as a developer, you basically need to loop through all the fields ... generates in order to figure out how best to extract the information you need ... This reply is posted in the Newsgroup; please post any follow question or reply ...
    (microsoft.public.office.developer.automation)
  • Re: Speed of interfaces vs inheritance
    ... I seem to recall, in years past, that the interface approach was slower. ... Instead of your code doing the loop and worrying about performance, ... public void run{ ... HttpServer h = new HttpServer; ...
    (comp.lang.java.programmer)
  • Re: Sysctl Naming
    ... 1 for each network interface. ... purposes so wanted to create them in this loop. ... driver in CURRENT inserts a node into each CPU device's sysctl tree. ...
    (freebsd-hackers)