dbs2(19)%
more memtest.c memtest.out*
::::::::::::::
memtest.c
::::::::::::::
/*
memory testing program
build with timepack.c, also supplied, and
its timepack.h
header file.
*/
#include
<stdio.h>
#include
<stdlib.h>
#include
"timepack.h"
#define
KB 1024
void
experiment(char *arr, long nbytes, int random);
int
main(int argc, char* argv[])
{
long size;
void* data;
int usec;
if (argc != 2) {
printf("Usage: %s #KB to
malloc\n", argv[0]);
return 1;
}
printf("sizeof long = %ld\n",
sizeof(long));
printf("sizeof long long =
%ld\n", sizeof(long long));
printf("Size to be malloced is:
%sKB\n", argv[1]);
size = (long)atoi(argv[1]);
size *= KB;
starttimer();
data = (void*)malloc(size);
stoptimer(&usec);
if (data)
printf("Malloc successfully!
in %d usecs\n", usec);
else
printf("Malloc
failed!\n");
/* clear memory */
starttimer();
memset(data, 0, size);
stoptimer(&usec);
printf("allocated/cleared memory
in %d usecs\n", usec);
/* here, loop through cases (len = #KB)
by powers of 2 up to size
for each case, call function
"experiment(char *arr, int nbytes)"
where nbytes = len*1024 for each
case. In experiment,
read nbytes bytes of the array, say
adding them all up,
and repeats this 10 times, and then
prints out the time.
*/
int len;
for(len = 1; len <= atoi(argv[1]);
len*=2) {
experiment(data, len, 0); /*
sequential */
}
return 0;
}
long
loop(long *arr, long nK, int random);
void
experiment(char *arr, long nK, int random)
{
int j, usec;
int sum = 0;
int i;
/* warm up */
loop((long *)arr, nK, 0);
starttimer();
for(j = 0; j < 10; j++) {
loop((long *)arr, nK, random);
}
stoptimer(&usec);
printf("summed %ld KB of memory 10x at
in %d usecs, rate = %ld bytes/usec\n", nK, usec, (nK*1024*10)
/usec);
}
long
loop(long *arr, long nK, int random)
<--(random is not in use)
{
long i, sum;
long nbytes = nK*1024;
for(i = 0; i < nbytes/sizeof(long); i++)
{
sum += arr[i];
}
return sum;
}
::::::::::::::
memtest.out-opt
::::::::::::::
sf06.cs.umb.edu$
a.out 3000000 <--a.out build
with gcc –O2 memtest.c timepack.c
sizeof
long = 8
sizeof
long long = 8
Size
to be malloced is: 3000000KB
Malloc
successfully! in 61 usecs
allocated/cleared
memory in 4017413 usecs
summed
1 KB of memory 10x at in 2 usecs, rate = 5120 bytes/usec
summed
2 KB of memory 10x at in 4 usecs, rate = 5120 bytes/usec
summed
4 KB of memory 10x at in 7 usecs, rate = 5851 bytes/usec
summed
8 KB of memory 10x at in 17 usecs, rate = 4818 bytes/usec
summed
16 KB of memory 10x at in 25 usecs, rate = 6553 bytes/usec
summed
32 KB of memory 10x at in 48 usecs, rate = 6826 bytes/usec
summed
64 KB of memory 10x at in 95 usecs, rate = 6898 bytes/usec
summed
128 KB of memory 10x at in 200 usecs, rate = 6553 bytes/usec
summed
256 KB of memory 10x at in 388 usecs, rate = 6756 bytes/usec
summed
512 KB of memory 10x at in 776 usecs, rate = 6756 bytes/usec
summed
1024 KB of memory 10x at in 2074 usecs, rate = 5055 bytes/usec <--rate
starts dropping: cache size = 1MB
summed
2048 KB of memory 10x at in 6926 usecs, rate = 3027 bytes/usec
summed
4096 KB of memory 10x at in 14115 usecs, rate = 2971 bytes/usec
summed
8192 KB of memory 10x at in 28111 usecs, rate = 2984 bytes/usec
summed
16384 KB of memory 10x at in 56389 usecs, rate = 2975 bytes/usec
summed
32768 KB of memory 10x at in 112850 usecs, rate = 2973 bytes/usec
summed
65536 KB of memory 10x at in 225893 usecs, rate = 2970 bytes/usec
summed
131072 KB of memory 10x at in 451728 usecs, rate = 2971 bytes/usec
summed
262144 KB of memory 10x at in 903632 usecs, rate = 2970 bytes/usec
summed
524288 KB of memory 10x at in 1806709 usecs, rate = 2971 bytes/usec
summed
1048576 KB of memory 10x at in 3614080 usecs, rate = 2970 bytes/usec
summed
2097152 KB of memory 10x at in 8164300 usecs, rate = 2630 bytes/usec
::::::::::::::
memtest.out-unopt
::::::::::::::
sf06.cs.umb.edu$
gcc memtest.c timepack.c
memtest.c:
In function 'main':
memtest.c:38:
warning: incompatible implicit declaration of built-in function 'memset'
sf06.cs.umb.edu$
a.out 3000000
sizeof
long = 8
sizeof
long long = 8
Size
to be malloced is: 3000000KB
Malloc
successfully! in 59 usecs
allocated/cleared
memory in 3851899 usecs
summed
1 KB of memory 10x at in 7 usecs, rate = 1462 bytes/usec
summed
2 KB of memory 10x at in 14 usecs, rate = 1462 bytes/usec
summed
4 KB of memory 10x at in 27 usecs, rate = 1517 bytes/usec
summed
8 KB of memory 10x at in 53 usecs, rate = 1545 bytes/usec
summed
16 KB of memory 10x at in 104 usecs, rate = 1575 bytes/usec
summed
32 KB of memory 10x at in 208 usecs, rate = 1575 bytes/usec
summed
64 KB of memory 10x at in 415 usecs, rate = 1579 bytes/usec
summed
128 KB of memory 10x at in 847 usecs, rate = 1547 bytes/usec
summed
256 KB of memory 10x at in 1698 usecs, rate = 1543 bytes/usec
summed
512 KB of memory 10x at in 3384 usecs, rate = 1549 bytes/usec
summed
1024 KB of memory 10x at in 6921 usecs, rate = 1515 bytes/usec <--nothing much here
summed
2048 KB of memory 10x at in 14367 usecs, rate = 1459 bytes/usec
summed
4096 KB of memory 10x at in 28926 usecs, rate = 1450 bytes/usec
summed
8192 KB of memory 10x at in 57940 usecs, rate = 1447 bytes/usec
summed
16384 KB of memory 10x at in 115924 usecs, rate = 1447 bytes/usec
summed
32768 KB of memory 10x at in 231854 usecs, rate = 1447 bytes/usec
summed
65536 KB of memory 10x at in 463861 usecs, rate = 1446 bytes/usec
summed
131072 KB of memory 10x at in 927523 usecs, rate = 1447 bytes/usec
summed
262144 KB of memory 10x at in 1854980 usecs, rate = 1447 bytes/usec