26 December 2011

Timer Concept Using Preprocessor


#include <time.h>
#include <stdlib.h>
clock_t startm, stopm;
#define START if ( (startm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define STOP if ( (stopm = clock()) == -1) {printf("Error calling clock");exit(1);}
#define PRINTTIME printf( "%6.3f seconds used by the processor.", ((double)stopm-startm)/CLOCKS_PER_SEC);




Usage:

main() {
     START;
     // Do stuff you want to time
     STOP;
     PRINTTIME;
}

No comments :

Post a Comment

Popular Posts