#include #include #include @interface MaClasse : NSObject - (void) appel; @end @implementation MaClasse - (void) appel { } @end static void appel (void) { } static inline void appel_enligne (void) { } #define NB_APPELS 1000000000 #define TEST_APPELS(_nom, _appel) \ { \ int i; \ struct timeval debut, fin, diff; \ \ gettimeofday (&debut, NULL); \ for (i = 0; i < NB_APPELS; i++) \ (_appel); \ gettimeofday (&fin, NULL); \ \ timersub (&fin, &debut, &diff); \ printf ("Temps appels %s : %.1fs\n", (_nom), \ (double) diff.tv_sec + (double) diff.tv_usec / 100000.0); \ } int main (int argc, char **argv) { TEST_APPELS("macro", 1); TEST_APPELS("C", appel()); TEST_APPELS("C en ligne", appel_enligne()); MaClasse *obj = [[MaClasse alloc] init]; TEST_APPELS("Objective-C", [obj appel]); IMP methode = [obj methodForSelector: @selector(appel)]; TEST_APPELS("Objective-C en cache", methode(obj, @selector(appel))); return EXIT_SUCCESS; }