Sunday, October 19, 2008

simple malloc test for systems comparison

#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
static int *intarr;
static const int iMax = 200000;
static const int iiMax = 500000;
int main()
{
int i;
for(i=0; i<iiMax; i++)
{
intarr = (int *) malloc(sizeof(int)*iMax);
if (errno)
{
perror(sys_errlist[errno]);
break;
}
else
printf("ok\n");
}
char c;
printf("%d",i*iMax);
scanf("%c",&c);
return 0;
}



output of top on centos:


top - 20:53:09 up 2 days, 22:52, 9 users, load average: 2.74, 1.13, 0.77
Tasks: 168 total, 1 running, 167 sleeping, 0 stopped, 0 zombie
Cpu(s): 3.6%us, 1.7%sy, 0.0%ni, 94.2%id, 0.3%wa, 0.2%hi, 0.0%si, 0.0%st

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
28315 rtg 16 0 290g 999m 596 S 0 53.1 0:06.64 my_tst
4296 rtg 15 0 451m 5268 2360 S 0 0.3 0:20.46 nautilus

No comments: