Accueil > > > OPTIMISATION DES CALLBACKS C++ RÉSOLUS À LA COMPILATION.
OPTIMISATION DES CALLBACKS C++ RÉSOLUS À LA COMPILATION.
Information sur la source
Description
Voici une classe de base pour réaliser simplement des callbacks "statiques" en C++. J'entends par "statiques", des callbacks pouvant être résolus au moment de la compilation.
La configuration de l'objet et de la fonction membre appelés est réalisée par template. Ainsi la mise en oeuvre du callback n'induit aucune surcharge à l'execution (à condition d'utiliser un compilateur/optimiseur performant).
Source
- //////////////////////////////////////////////////////////////////////
- // Functor callback :
- //////////////////////////////////////////////////////////////////////
-
- #include<exception>
- using std::exception;
-
- // Configuration :
- // - du type d'objet appelé,
- // - du type de la valeur de retour de la fonction membre appelée,
- // - du type de l'argument de la fonction membre appelée,
- // - du pointeur de fonction membre.
-
- // Callback statique vers une fonction membre non const :
- template<
- typename t_class,
- typename t_return,
- typename t_argument,
- t_return ( t_class::*fm )( t_argument )
- >
- struct t_callback
- {
- t_callback( t_class& c ) : _callback_class( c ) {}
- inline t_return operator()( t_argument arg )
- {
- return (_callback_class.*fm)( arg );
- }
- private:
- t_class& _callback_class;
- };
-
- // Callback statique vers une fonction membre const :
- template<
- typename t_class,
- typename t_return,
- typename t_argument,
- t_return ( t_class::*fm )( t_argument ) const
- >
- struct t_callback_const
- {
- t_callback_const( const t_class& c ) : _callback_class( c ) {}
- inline t_return operator()( t_argument arg ) const
- {
- return (_callback_class.*fm)( arg );
- }
- private:
- const t_class& _callback_class;
- };
-
- // Callback "dynamique" vers une fonction membre non const :
- template <
- typename t_class,
- typename t_return,
- typename t_argument
- >
- struct t_callback_dyn
- {
- // exception
- struct bad_instance : exception
- {
- const char* what() const throw() { return "bad instance"; }
- };
- // exception
- struct bad_method : exception
- {
- const char* what() const throw() { return "bad method"; }
- };
- // type de fonction membre
- typedef t_return ( t_class::*t_method )( t_argument );
- // constructeur
- t_callback_dyn( t_class* class_instance = 0, t_method method = 0 ) :
- _class_instance( class_instance ),
- _method( method )
- {
-
- }
- void set( t_class* class_instance, t_method method )
- {
- _class_instance = class_instance;
- _method = method;
- }
- inline t_return operator()( t_argument parameter )
- {
- return ( _class_instance->*_method )( parameter );
- }
- inline t_return call( t_argument parameter )
- {
- if( _class_instance == 0 )
- throw bad_instance();
- if( _method == 0 )
- throw bad_method();
- return ( _class_instance->*_method )( parameter );
- }
- inline t_return call_wo_throw( t_argument parameter ) throw()
- {
- try
- {
- if( _class_instance != 0 && _method != 0 )
- return ( _class_instance->*_method )( parameter );
- else
- return t_return();
- }
- catch(...) { return t_return(); }
- }
- private:
- t_class* _class_instance;
- t_method _method;
-
- };
-
- // Callback "dynamique" vers une fonction membre const :
- template <
- typename t_class,
- typename t_return,
- typename t_argument
- >
- struct t_callback_dyn_const
- {
- // exception
- struct bad_instance : exception
- {
- const char* what() const throw() { return "bad instance"; }
- };
- // exception
- struct bad_method : exception
- {
- const char* what() const throw() { return "bad method"; }
- };
- // type de fonction membre
- typedef t_return ( t_class::*t_method )( t_argument ) const;
- // constructeur
- t_callback_dyn_const( t_class* class_instance = 0, t_method method = 0 ) :
- _class_instance( class_instance ),
- _method( method )
- {
-
- }
- void set( t_class* class_instance, t_method method )
- {
- _class_instance = class_instance;
- _method = method;
- }
- inline t_return operator()( t_argument parameter ) const
- {
- return ( _class_instance->*_method )( parameter );
- }
- inline t_return call( t_argument parameter ) const
- {
- if( _class_instance == 0 )
- throw bad_instance();
- if( _method == 0 )
- throw bad_method();
- return ( _class_instance->*_method )( parameter );
- }
- inline t_return call_wo_throw( t_argument parameter ) const throw()
- {
- try
- {
- if( _class_instance != 0 && _method != 0 )
- return ( _class_instance->*_method )( parameter );
- else
- return t_return();
- }
- catch(...) { return t_return(); }
- }
- private:
- t_class* _class_instance;
- t_method _method;
-
- };
-
-
- //////////////////////////////////////////////////////////////////////
- // Mise en oeuvre et exemples
- //////////////////////////////////////////////////////////////////////
-
- // Variables de mesure des performances
- const unsigned int nb_tests = 200;
- const unsigned int nb_iterations = 200000000;
-
- #include<vector>
- #include<sstream>
- #include<iostream>
- #include<algorithm>
- #include<functional>
- #include<numeric>
- #include<ctime>
- using namespace std;
-
- // Pour l'exemple, les fonctions membres appellées ont le prototype :
- // "int f( const int& )" ou "int f( const int& ) const"
-
- // Objet appelé n°1 pour l'exemple.
- struct A
- {
- A( const int& n ) : _coef( n ) {}
- int fa( const int& n ) { return _coef + n; }
- private:
- int _coef;
- };
-
- // Objet appelé n°2 pour l'exemple.
- struct B
- {
- B( const int& n ) : _coef( n ) {}
- int fb( const int& n ) { return _coef + n; }
- private:
- int _coef;
- };
-
- // Objet appelé n°3 pour l'exemple.
- struct C
- {
- C( const int& n ) : _coef( n ) {}
- int fc( const int& n ) const { return _coef + n; }
- private:
- int _coef;
- };
-
- // Objet appelant sans callback (appel codé en dur) pour l'exemple.
- struct W
- {
- W( A& a ) : _a( a ) {}
- void event() { _a.fa( 888 ); }
- private:
- A& _a;
- };
-
- //////////////////////////////////////////////////////////////////////
- //
- // Si ce n'est pas A::fa mais B::fb qu'il faut appeler,
- // la classe W doit être recoder en conséquence.
- //
- // Pour mettre en oeuvre un callback statique, il faut preciser au
- // moment de la compilation (par template), le type de l'objet appelé
- // et passer le pointeur vers la fonction membre appelée.
- // A la construction de la classe intégrant un callback, il faut
- // passer par référence une instance de l'objet appelé.
- // A l'utilisation, le callback se manipule comme la fonction membre
- // appelée (operateur ()).
- //
- //////////////////////////////////////////////////////////////////////
-
- // Objet appelant avec callback "statique" (fonction membre non const)
- template< typename t_class, int ( t_class::*fm )( const int& ) >
- struct X
- {
- X( t_class& c ) : callback( c ) {}
- void event() { callback( 888 ); }
- private:
- t_callback< t_class, int, const int&, fm > callback;
- };
-
- // Objet appelant avec callback "statique" (fonction membre const)
- template< typename t_class, int ( t_class::*fm )( const int& ) const >
- struct Y
- {
- Y( t_class& c ) : callback( c ) {}
- void event() { callback( 888 ); }
- private:
- t_callback_const< t_class, int, const int&, fm > callback; // callback
- };
-
- // Objet appelant avec callback "dynamique" (fonction membre non const)
- // sans test class/methode
- template< typename t_class >
- struct Z
- {
- typedef int ( t_class::*fm )( const int& );
- Z( t_class& c, fm f ) : callback( &c, f ) {}
- void event() { callback( 888 ); }
- private:
- t_callback_dyn< t_class, int, const int& > callback;
- };
-
- // Objet appelant avec callback "dynamique" (fonction membre non const)
- // avec test class/methode
- template< typename t_class >
- struct Zt
- {
- typedef int ( t_class::*fm )( const int& );
- Zt( t_class& c, fm f ) : callback( &c, f ) {}
- void event() { callback.call( 888 ); }
- private:
- t_callback_dyn< t_class, int, const int& > callback;
- };
-
- // Objet appelant avec callback "dynamique" (fonction membre const)
- // sans test class/methode
- template< typename t_class >
- struct Zc
- {
- typedef int ( t_class::*fm )( const int& ) const;
- Zc( t_class& c, fm f ) : callback( &c, f ) {}
- void event() { callback( 888 ); }
- private:
- t_callback_dyn_const< t_class, int, const int& > callback;
- };
-
- // Objet appelant avec callback "dynamique" (fonction membre const)
- // sans test class/methode
- template< typename t_class >
- struct Ztc
- {
- typedef int ( t_class::*fm )( const int& ) const;
- Ztc( t_class& c, fm f ) : callback( &c, f ) {}
- void event() { callback.call( 888 ); }
- private:
- t_callback_dyn_const< t_class, int, const int& > callback;
- };
-
-
- int main()
- {
- // Varaibles de mesure des performances
- vector<clock_t> duree_ss_callback;
- vector<clock_t> duree_av_callback_sta;
- vector<clock_t> duree_av_callback_stac;
- vector<clock_t> duree_av_callback_dyn;
- vector<clock_t> duree_av_callback_dynt;
- vector<clock_t> duree_av_callback_dync;
- vector<clock_t> duree_av_callback_dyntc;
-
- // Objets appelés :
- A a( 12 );
- //B b( 12 );
- C c( 12 );
-
- // Boucle de test
- for( int repetition = nb_tests; repetition != 0; repetition-- )
- {
-
- // Test de performance avec un objet appelant sans callback :
- {
- W w( a );
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- w.event();
- duree_ss_callback.push_back( clock() - debut );
- }
- // ... pas possible d'appeler une autre fonction membre de A, ou un autre objet sans recoder...
-
- // Test de performance avec un objet appelant avec callback statique (non const):
- {
- X<A, &A::fa> xa( a ); // Objet configuré pour appeler A::fa
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- xa.event();
- duree_av_callback_sta.push_back( clock() - debut );
- }
-
- // Test de performance avec un objet appelant avec callback statique (non const):
- {
- Y<C, &C::fc> yc( c ); // Objet configuré pour appeler C::fc (methode const)
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- yc.event();
- duree_av_callback_stac.push_back( clock() - debut );
- }
-
- // Test de performance avec un objet appelant avec callback dynamique (non const) (ss test class/methode):
- {
- Z<A> za( a, &A::fa ); // Objet configuré pour appeler A::fa
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- za.event();
- duree_av_callback_dyn.push_back( clock() - debut );
- }
-
- // Test de performance avec un objet appelant avec callback dynamique (non const) (av test class/methode):
- {
- Zt<A> zta( a, &A::fa ); // Objet configuré pour appeler A::fa
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- zta.event();
- duree_av_callback_dynt.push_back( clock() - debut );
- }
-
- // Test de performance avec un objet appelant avec callback dynamique (const) (ss test class/methode):
- {
- Zc<C> zc( c, &C::fc ); // Objet configuré pour appeler A::fa
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- zc.event();
- duree_av_callback_dync.push_back( clock() - debut );
- }
-
- // Test de performance avec un objet appelant avec callback dynamique (const) (ac test class/methode):
- {
- Ztc<C> ztc( c, &C::fc ); // Objet configuré pour appeler A::fa
- clock_t debut = clock();
- for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
- ztc.event();
- duree_av_callback_dyntc.push_back( clock() - debut );
- }
- }
-
- // affichage des performances
- cout << "Temps d'execution sans callback : " << accumulate( duree_ss_callback.begin(), duree_ss_callback.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback statique (non const) : " << accumulate( duree_av_callback_sta.begin(), duree_av_callback_sta.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback statique (const) : " << accumulate( duree_av_callback_stac.begin(), duree_av_callback_stac.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback dynamique (non const)(ss test) : " << accumulate( duree_av_callback_dyn.begin(), duree_av_callback_dyn.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback dynamique (non const)(av test) : " << accumulate( duree_av_callback_dynt.begin(), duree_av_callback_dynt.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback dynamique (const)(ss test) : " << accumulate( duree_av_callback_dync.begin(), duree_av_callback_dync.end(), 0 ) << "ms" << endl;
- cout << "Temps d'execution avec callback dynamique (const)(av test) : " << accumulate( duree_av_callback_dyntc.begin(), duree_av_callback_dyntc.end(), 0 ) << "ms" << endl;
- }
-
-
//////////////////////////////////////////////////////////////////////
// Functor callback :
//////////////////////////////////////////////////////////////////////
#include<exception>
using std::exception;
// Configuration :
// - du type d'objet appelé,
// - du type de la valeur de retour de la fonction membre appelée,
// - du type de l'argument de la fonction membre appelée,
// - du pointeur de fonction membre.
// Callback statique vers une fonction membre non const :
template<
typename t_class,
typename t_return,
typename t_argument,
t_return ( t_class::*fm )( t_argument )
>
struct t_callback
{
t_callback( t_class& c ) : _callback_class( c ) {}
inline t_return operator()( t_argument arg )
{
return (_callback_class.*fm)( arg );
}
private:
t_class& _callback_class;
};
// Callback statique vers une fonction membre const :
template<
typename t_class,
typename t_return,
typename t_argument,
t_return ( t_class::*fm )( t_argument ) const
>
struct t_callback_const
{
t_callback_const( const t_class& c ) : _callback_class( c ) {}
inline t_return operator()( t_argument arg ) const
{
return (_callback_class.*fm)( arg );
}
private:
const t_class& _callback_class;
};
// Callback "dynamique" vers une fonction membre non const :
template <
typename t_class,
typename t_return,
typename t_argument
>
struct t_callback_dyn
{
// exception
struct bad_instance : exception
{
const char* what() const throw() { return "bad instance"; }
};
// exception
struct bad_method : exception
{
const char* what() const throw() { return "bad method"; }
};
// type de fonction membre
typedef t_return ( t_class::*t_method )( t_argument );
// constructeur
t_callback_dyn( t_class* class_instance = 0, t_method method = 0 ) :
_class_instance( class_instance ),
_method( method )
{
}
void set( t_class* class_instance, t_method method )
{
_class_instance = class_instance;
_method = method;
}
inline t_return operator()( t_argument parameter )
{
return ( _class_instance->*_method )( parameter );
}
inline t_return call( t_argument parameter )
{
if( _class_instance == 0 )
throw bad_instance();
if( _method == 0 )
throw bad_method();
return ( _class_instance->*_method )( parameter );
}
inline t_return call_wo_throw( t_argument parameter ) throw()
{
try
{
if( _class_instance != 0 && _method != 0 )
return ( _class_instance->*_method )( parameter );
else
return t_return();
}
catch(...) { return t_return(); }
}
private:
t_class* _class_instance;
t_method _method;
};
// Callback "dynamique" vers une fonction membre const :
template <
typename t_class,
typename t_return,
typename t_argument
>
struct t_callback_dyn_const
{
// exception
struct bad_instance : exception
{
const char* what() const throw() { return "bad instance"; }
};
// exception
struct bad_method : exception
{
const char* what() const throw() { return "bad method"; }
};
// type de fonction membre
typedef t_return ( t_class::*t_method )( t_argument ) const;
// constructeur
t_callback_dyn_const( t_class* class_instance = 0, t_method method = 0 ) :
_class_instance( class_instance ),
_method( method )
{
}
void set( t_class* class_instance, t_method method )
{
_class_instance = class_instance;
_method = method;
}
inline t_return operator()( t_argument parameter ) const
{
return ( _class_instance->*_method )( parameter );
}
inline t_return call( t_argument parameter ) const
{
if( _class_instance == 0 )
throw bad_instance();
if( _method == 0 )
throw bad_method();
return ( _class_instance->*_method )( parameter );
}
inline t_return call_wo_throw( t_argument parameter ) const throw()
{
try
{
if( _class_instance != 0 && _method != 0 )
return ( _class_instance->*_method )( parameter );
else
return t_return();
}
catch(...) { return t_return(); }
}
private:
t_class* _class_instance;
t_method _method;
};
//////////////////////////////////////////////////////////////////////
// Mise en oeuvre et exemples
//////////////////////////////////////////////////////////////////////
// Variables de mesure des performances
const unsigned int nb_tests = 200;
const unsigned int nb_iterations = 200000000;
#include<vector>
#include<sstream>
#include<iostream>
#include<algorithm>
#include<functional>
#include<numeric>
#include<ctime>
using namespace std;
// Pour l'exemple, les fonctions membres appellées ont le prototype :
// "int f( const int& )" ou "int f( const int& ) const"
// Objet appelé n°1 pour l'exemple.
struct A
{
A( const int& n ) : _coef( n ) {}
int fa( const int& n ) { return _coef + n; }
private:
int _coef;
};
// Objet appelé n°2 pour l'exemple.
struct B
{
B( const int& n ) : _coef( n ) {}
int fb( const int& n ) { return _coef + n; }
private:
int _coef;
};
// Objet appelé n°3 pour l'exemple.
struct C
{
C( const int& n ) : _coef( n ) {}
int fc( const int& n ) const { return _coef + n; }
private:
int _coef;
};
// Objet appelant sans callback (appel codé en dur) pour l'exemple.
struct W
{
W( A& a ) : _a( a ) {}
void event() { _a.fa( 888 ); }
private:
A& _a;
};
//////////////////////////////////////////////////////////////////////
//
// Si ce n'est pas A::fa mais B::fb qu'il faut appeler,
// la classe W doit être recoder en conséquence.
//
// Pour mettre en oeuvre un callback statique, il faut preciser au
// moment de la compilation (par template), le type de l'objet appelé
// et passer le pointeur vers la fonction membre appelée.
// A la construction de la classe intégrant un callback, il faut
// passer par référence une instance de l'objet appelé.
// A l'utilisation, le callback se manipule comme la fonction membre
// appelée (operateur ()).
//
//////////////////////////////////////////////////////////////////////
// Objet appelant avec callback "statique" (fonction membre non const)
template< typename t_class, int ( t_class::*fm )( const int& ) >
struct X
{
X( t_class& c ) : callback( c ) {}
void event() { callback( 888 ); }
private:
t_callback< t_class, int, const int&, fm > callback;
};
// Objet appelant avec callback "statique" (fonction membre const)
template< typename t_class, int ( t_class::*fm )( const int& ) const >
struct Y
{
Y( t_class& c ) : callback( c ) {}
void event() { callback( 888 ); }
private:
t_callback_const< t_class, int, const int&, fm > callback; // callback
};
// Objet appelant avec callback "dynamique" (fonction membre non const)
// sans test class/methode
template< typename t_class >
struct Z
{
typedef int ( t_class::*fm )( const int& );
Z( t_class& c, fm f ) : callback( &c, f ) {}
void event() { callback( 888 ); }
private:
t_callback_dyn< t_class, int, const int& > callback;
};
// Objet appelant avec callback "dynamique" (fonction membre non const)
// avec test class/methode
template< typename t_class >
struct Zt
{
typedef int ( t_class::*fm )( const int& );
Zt( t_class& c, fm f ) : callback( &c, f ) {}
void event() { callback.call( 888 ); }
private:
t_callback_dyn< t_class, int, const int& > callback;
};
// Objet appelant avec callback "dynamique" (fonction membre const)
// sans test class/methode
template< typename t_class >
struct Zc
{
typedef int ( t_class::*fm )( const int& ) const;
Zc( t_class& c, fm f ) : callback( &c, f ) {}
void event() { callback( 888 ); }
private:
t_callback_dyn_const< t_class, int, const int& > callback;
};
// Objet appelant avec callback "dynamique" (fonction membre const)
// sans test class/methode
template< typename t_class >
struct Ztc
{
typedef int ( t_class::*fm )( const int& ) const;
Ztc( t_class& c, fm f ) : callback( &c, f ) {}
void event() { callback.call( 888 ); }
private:
t_callback_dyn_const< t_class, int, const int& > callback;
};
int main()
{
// Varaibles de mesure des performances
vector<clock_t> duree_ss_callback;
vector<clock_t> duree_av_callback_sta;
vector<clock_t> duree_av_callback_stac;
vector<clock_t> duree_av_callback_dyn;
vector<clock_t> duree_av_callback_dynt;
vector<clock_t> duree_av_callback_dync;
vector<clock_t> duree_av_callback_dyntc;
// Objets appelés :
A a( 12 );
//B b( 12 );
C c( 12 );
// Boucle de test
for( int repetition = nb_tests; repetition != 0; repetition-- )
{
// Test de performance avec un objet appelant sans callback :
{
W w( a );
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
w.event();
duree_ss_callback.push_back( clock() - debut );
}
// ... pas possible d'appeler une autre fonction membre de A, ou un autre objet sans recoder...
// Test de performance avec un objet appelant avec callback statique (non const):
{
X<A, &A::fa> xa( a ); // Objet configuré pour appeler A::fa
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
xa.event();
duree_av_callback_sta.push_back( clock() - debut );
}
// Test de performance avec un objet appelant avec callback statique (non const):
{
Y<C, &C::fc> yc( c ); // Objet configuré pour appeler C::fc (methode const)
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
yc.event();
duree_av_callback_stac.push_back( clock() - debut );
}
// Test de performance avec un objet appelant avec callback dynamique (non const) (ss test class/methode):
{
Z<A> za( a, &A::fa ); // Objet configuré pour appeler A::fa
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
za.event();
duree_av_callback_dyn.push_back( clock() - debut );
}
// Test de performance avec un objet appelant avec callback dynamique (non const) (av test class/methode):
{
Zt<A> zta( a, &A::fa ); // Objet configuré pour appeler A::fa
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
zta.event();
duree_av_callback_dynt.push_back( clock() - debut );
}
// Test de performance avec un objet appelant avec callback dynamique (const) (ss test class/methode):
{
Zc<C> zc( c, &C::fc ); // Objet configuré pour appeler A::fa
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
zc.event();
duree_av_callback_dync.push_back( clock() - debut );
}
// Test de performance avec un objet appelant avec callback dynamique (const) (ac test class/methode):
{
Ztc<C> ztc( c, &C::fc ); // Objet configuré pour appeler A::fa
clock_t debut = clock();
for( unsigned int iteration = nb_iterations; iteration !=0; iteration-- )
ztc.event();
duree_av_callback_dyntc.push_back( clock() - debut );
}
}
// affichage des performances
cout << "Temps d'execution sans callback : " << accumulate( duree_ss_callback.begin(), duree_ss_callback.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback statique (non const) : " << accumulate( duree_av_callback_sta.begin(), duree_av_callback_sta.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback statique (const) : " << accumulate( duree_av_callback_stac.begin(), duree_av_callback_stac.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback dynamique (non const)(ss test) : " << accumulate( duree_av_callback_dyn.begin(), duree_av_callback_dyn.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback dynamique (non const)(av test) : " << accumulate( duree_av_callback_dynt.begin(), duree_av_callback_dynt.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback dynamique (const)(ss test) : " << accumulate( duree_av_callback_dync.begin(), duree_av_callback_dync.end(), 0 ) << "ms" << endl;
cout << "Temps d'execution avec callback dynamique (const)(av test) : " << accumulate( duree_av_callback_dyntc.begin(), duree_av_callback_dyntc.end(), 0 ) << "ms" << endl;
}
Conclusion
Limitation :
- Ne compile pas sous VC6 (testé avec MinGW, Cygwin et Visual.Net-7.1).
Observation :
- Excellent niveau de performance avec Visual.Net-7.1 pour les callbacks statiques (inlining poussé),
- Optimisation peu convaincante avec GCC/win32 (Cygwin et MinGW).
A faire :
- Améliorer la génération et la propagation des exceptions dans toutes les classes callback.
Toutes remarques sont les bienvenues ! ;-)
Historique
- 26 décembre 2004 22:37:09 :
- Mise en forme.
- 26 décembre 2004 23:03:07 :
- Modification du titre.
- 27 décembre 2004 21:20:55 :
- Ajout d'une seconde classe callback capable d'appeler une fonction membre const.
- 27 décembre 2004 21:21:47 :
- Mise en forme.
- 27 décembre 2004 21:23:14 :
- Mise en forme (oui, je persiste!)
- 27 décembre 2004 23:15:11 :
- Correction de t_callback_const.
- 28 décembre 2004 13:58:03 :
- Code (mesure des performances) & Screenshot (resultat avec compilateur .Net 2003 - VC7).
- 29 décembre 2004 12:39:24 :
- Ajout d'une classe callback dynamique adaptée aux fonctions membres const.
Ajout d'une fonction membre dans la classe callback dynamique sans test de validité du callback.
Ajout de plusieurs mesures de performances (callback dynamique av/ss const, av/ss test validité).
Amélioration du mécanisme d'exception de la classe callback dynamique.
Mise à jour du screenchot des resultats du test (VC7.1 / -O2).
Mise en forme.
- 29 décembre 2004 12:46:07 :
- Correction d'erreur.
- 30 décembre 2004 23:47:56 :
- Ajout d'une fonction membre dans les classes callback dynamiques en throw().
- 31 décembre 2004 09:09:05 :
- Correction d'erreur.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
[DESIGN PATTERNS] PARTIE 2: DIP: DEPENDENCY INVERSION PRINCIPLE[DESIGN PATTERNS] PARTIE 2: DIP: DEPENDENCY INVERSION PRINCIPLE par tja
C'est le dernier principe des principes du Design Orienté Objet (The Principles of Object Oriented Design) fondés par Robert C. Martin plus connu sous le pseudonyme d'Uncle Bob.
l'image empruntée de LosTechies.
Je ne traite pas les principes dans...
Cliquez pour lire la suite de l'article par tja TECHDAYS PARIS 2010 : SHAREPOINT 2010 POUR LES DéVELOPPEURSTECHDAYS PARIS 2010 : SHAREPOINT 2010 POUR LES DéVELOPPEURS par ROMELARD Fabrice
Animé par: Laurent Cotton Le développement dans SharePoint 2010 passe par plusieurs axes qui seront évoqués dans cette session, mais plus particulièrement les développements simples lié au besoin Business Business Connectivity Services Ce BCS es...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLEINIèRE DERNIER JOURTECHDAYS PARIS 2010 : PLEINIèRE DERNIER JOUR par ROMELARD Fabrice
Cette session est la dernière pleinière de ces 3 jours de TechDays Paris 2010. Généralement, cette troisième journée est plus axée sur l'avenir vu par Microsoft. Après un retour sur l'avenir vu par la Science Fiction ou par ...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice UNE JOLIE-HORLOGE ET PAS QU'UN PEU !UNE JOLIE-HORLOGE ET PAS QU'UN PEU ! par neodante
Pour les possesseurs d'iPhone, ça y est Bijin Tokei - qui se traduit littéralement en Français par " Jolie Horloge " - est arrivé et GRATUITEMENT s'il vous plaît ! Après la version Tokyo, Hokkaido, night club, racing, Gal, "pour les mademoiselles'", . voi...
Cliquez pour lire la suite de l'article par neodante TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
RE : WIN APIRE : WIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|