summaryrefslogtreecommitdiffstats
path: root/tools/test
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>1995-10-15 12:29:12 +0000
committerphk <phk@FreeBSD.org>1995-10-15 12:29:12 +0000
commitc9a551ca260656ce6147c083752a41f69c857ce3 (patch)
tree3febede4eb17e84dd577de84662d6d01874dc702 /tools/test
parent808912e9eb4e5e942c8287ec91734540cfdea4df (diff)
downloadFreeBSD-src-c9a551ca260656ce6147c083752a41f69c857ce3.zip
FreeBSD-src-c9a551ca260656ce6147c083752a41f69c857ce3.tar.gz
malloc.c A program to benchmark and test malloc.
Diffstat (limited to 'tools/test')
-rw-r--r--tools/test/README2
-rw-r--r--tools/test/malloc/Makefile23
-rw-r--r--tools/test/malloc/malloc.c43
3 files changed, 68 insertions, 0 deletions
diff --git a/tools/test/README b/tools/test/README
index c481f57..7198003 100644
--- a/tools/test/README
+++ b/tools/test/README
@@ -4,3 +4,5 @@ A test program is one that will excercise a particular bit of the system
and try to break it and/or measuring performance on it.
Please make a subdir per program, and add a brief description to this file.
+
+malloc A program to test and benchmark malloc().
diff --git a/tools/test/malloc/Makefile b/tools/test/malloc/Makefile
new file mode 100644
index 0000000..3cf3ee0
--- /dev/null
+++ b/tools/test/malloc/Makefile
@@ -0,0 +1,23 @@
+PROG= malloc
+NOMAN= sorry
+
+libcmalloc:
+ make clean
+ make "CFLAGS=-O2"
+ mv malloc libcmalloc
+ @echo
+ @csh -x -c "time ./libcmalloc 500000 2000 8192"
+ @csh -x -c "time ./libcmalloc 50000000 2000 8192"
+ @csh -x -c "time ./libcmalloc 500000 14000 8192"
+ @csh -x -c "time ./libcmalloc 20000000 20000 2048"
+
+gnumalloc:
+ make clean
+ make "CFLAGS=-lgnumalloc -O2"
+ mv malloc gnumalloc
+ @csh -x -c "time ./gnumalloc 500000 2000 8192"
+ @csh -x -c "time ./gnumalloc 50000000 2000 8192"
+ @csh -x -c "time ./gnumalloc 500000 14000 8192"
+ @csh -x -c "time ./gnumalloc 20000000 20000 2048"
+
+.include <bsd.prog.mk>
diff --git a/tools/test/malloc/malloc.c b/tools/test/malloc/malloc.c
new file mode 100644
index 0000000..a865b9e
--- /dev/null
+++ b/tools/test/malloc/malloc.c
@@ -0,0 +1,43 @@
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+
+u_long NBUCKETS = 2000;
+u_long NOPS = 200000;
+u_long NSIZE = (16*1024);
+
+char **foo;
+
+int
+main(int argc, char **argv)
+{
+ int i,j,k;
+
+ if (argc > 1) NOPS = strtoul(argv[1],0,0);
+ if (argc > 2) NBUCKETS = strtoul(argv[2],0,0);
+ if (argc > 3) NSIZE = strtoul(argv[3],0,0);
+ printf("BRK(0)=%x ",sbrk(0));
+ foo = malloc (sizeof *foo * NBUCKETS);
+ memset(foo,0,sizeof *foo * NBUCKETS);
+ for (i = 0 ; i < NOPS ; i++) {
+ j = rand() % NBUCKETS;
+ if (foo[j]) {
+ free(foo[j]);
+ foo[j] = 0;
+ } else {
+ k = rand() % NSIZE;
+ foo[j] = malloc(k);
+ foo[j][0] = 1;
+ }
+ }
+ printf("BRK(1)=%x ",sbrk(0));
+ for (j = 0 ; j < NBUCKETS ; j++) {
+ if (foo[j]) {
+ free(foo[j]);
+ foo[j] = 0;
+ }
+ }
+ printf("BRK(2)=%x NOPS=%lu NBUCKETS=%lu NSIZE=%lu\n",
+ sbrk(0),NOPS,NBUCKETS,NSIZE);
+ return 0;
+}
OpenPOWER on IntegriCloud