usage() {
puts(
"Usage:\n"
- "memtest [-c COUNT [-t [-D]] [-s MAXSIZE]]\n"
+ "memtest [-c COUNT [-t [-D]] [-s MAXSIZE] [-C COUNTCOUNT]]\n"
);
exit(1);
}
main(int argn, char *argv[]) {
MemoryContext *base, *child;
int i, SZ=32;
- int count=0, iscntx=0, flags=0;
+ int count=0, iscntx=0, flags=0, COUNT=1;
opentlog(TL_OPEN_STDERR,TL_DEBUG, NULL);
opterr=0;
- while((i=getopt(argn,argv,"s:Dc:ht")) != EOF) {
+ while((i=getopt(argn,argv,"s:Dc:htC:")) != EOF) {
switch(i) {
case 's':
SZ=atoi(optarg);
break;
+ case 'C':
+ COUNT=atoi(optarg);
+ break;
case 'c':
count=atoi(optarg);
break;
srandom(1);
if ( iscntx ) {
gettimeofday(&begin, NULL);
+ while(COUNT-- > 0) {
base = allocMemoryContext(NULL, flags);
for(i=0;i<count;i++) {
ptr = mcalloc(base, 1+random()%SZ );
}
freeMemoryContext(base);
+ }
printf("MC elapsed: %f sec\n", elapsedtime(&begin));
} else {
char **all, **allptr;
gettimeofday(&begin, NULL);
+ while(COUNT-- > 0) {
allptr=all=malloc(sizeof(char*)*count*2);
if ( !all )
tlog(TL_CRIT|TL_EXIT,"No memory");
allptr++;
}
free(all);
+ }
printf("Malloc elapsed: %f sec\n", elapsedtime(&begin));
}