OONumerics User :

From: Georg Holzmann (grh_at_[hidden])
Date: 2007-09-24 04:25:42


Hallo!

Thanks for all your answers !
(and sorry, the language I meant was C++)

> Probably the best thing to do is to use whatever method is best for
> you (virtual methods are ok), but to move the call *away* from the inner
> loops, i.e., instead of:

Yes, I think I wasted too much time thinking about this detail (should
have tuned the algorithm instead ;) - I bencharmked now various
approaches and if there is some work inside the virtual function, the
overhead is really insignificant.

Method | (1) | (2) |
-------------|-------------|-------------|
std | 2.25 sec | 4.19 sec |
CRTP | 0.225 sec | 4.175 sec |
FastDelegate | 2.53 sec | 4.21 sec |
FctPointer | 1.67 sec | 4.18 sec |
Mixins | 0.21 sec | 4.17 sec |
-------------|-------------|-------------|
(all on 32 bit linux, g++4.1.2)

(1) implements just a function call and returns i+1 (i is a variable of
that class) - looped 400 000 000 times

(2) implements a for loop of size 50 - looped 16 000 000 times:
        for(int i=1; i<=50; ++i)
        { i_ = i_*i_; }
        return i_;
and already here the overhead was not really significant (take +- 0.04
to all measurements of 2)

Std = standard strategy pattern with abstract base class
CRTP = template based approach (Curiously
Recurring Template Pattern), early binding
FastDelegate = using FastDelegates as in
http://www.codeproject.com/cpp/FastDelegate.asp
FctPointer = using simple functions and functionpointer in the context class
Mixins = mixin (template) based approach (early binding)

Two other methods would be using the boost.interfaces library
http://www.kangaroologic.com/interfaces/libs/interfaces/doc/index.html
or a similar method described here:
http://www.codeproject.com/cpp/retrofitpolymorphism2.asp.

So after all, I think I will use the standard strategy pattern, because
its the most flexible way!

Thank you,
LG
Georg