#include #include #include #include #include #include #include #include #include #define CHUNKSIZE 64 #define ITERATIONS 100000000 /* During this code, * I will be testing malloc+memset 0 VS calloc */ int main( int argc, char **argv ) { long int t; /* For timing */ char *mbuf; /* Testing buffer */ int i; /* Loop iterator */ t = (long int)time(0); for(i = 0; i < ITERATIONS; ++i) { mbuf = (char*) malloc(CHUNKSIZE); /* Allocate */ (void) memset((void *)mbuf, 0, CHUNKSIZE); /* Initalize */ (void) free((void *)mbuf); /* Free */ } printf("elapsed time is %ld secs (malloc&memset)\n", (long int)time(0) - t); t = (long int)time(0); for(i = 0; i < ITERATIONS; ++i) { mbuf = (char*) calloc(1, CHUNKSIZE); /* Allocate & Initalize */ (void) free((void *)mbuf); /* Free */ } printf("elapsed time is %ld secs (calloc)\n", (long int)time(0) - t); return 0; }