#include <stdio.h> #include <time.h> #define OP_COUNT 100000000 #define TIMES 10 int main () { clock_t nBeginning; clock_t nEnd; clock_t nCorrection; long nResult; long a; long nI; long nJ; nResult = 0; for (nJ = 0; nJ < TIMES * 2; nJ++) { /* Calcul du temps passé à boucler */ nBeginning = clock(); for (nI = 0; nI < OP_COUNT; nI++) { } nCorrection = clock() - nBeginning; printf("Correction = %d\n", (int)nCorrection); nBeginning = clock(); for (nI = 0; nI < OP_COUNT; nI++) { a = a + a * a; } nEnd = clock() - nBeginning; printf("Total = %d\n", (int)nEnd); nEnd = nEnd - nCorrection; /* On ne prend en compte que la deuxième moitié des tests */ if (nJ >= TIMES) nResult += nEnd; printf("Temps de calcul = %d\n", (int)nEnd); } printf("Moyenne = %ld clocks\n", nResult / TIMES); printf("CLOCKS_PER_SEC = %ld\n", CLOCKS_PER_SEC); printf("Temps pour %d d'operations = %f secondes\n", OP_COUNT * TIMES, (float)nResult / CLOCKS_PER_SEC); return 0; }
a = a + a * a;
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question#define TIMES 10
#define MSG "Hello world" ... printf(MSG);
printf("Hello world");