]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Add a malloc/free stress test.
authorNicholas Nethercote <njn@valgrind.org>
Sat, 17 Dec 2005 00:22:39 +0000 (00:22 +0000)
committerNicholas Nethercote <njn@valgrind.org>
Sat, 17 Dec 2005 00:22:39 +0000 (00:22 +0000)
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5362

perf/Makefile.am
perf/README
perf/heap.c [new file with mode: 0644]
perf/heap.vgperf [new file with mode: 0644]
perf/vg_perf.in

index d6898bfc6553ebb10966d7b9c4fc395a9d4ceabb..cd31e5f0b4537aa7b6f413375a70986bf765c9b8 100644 (file)
@@ -6,10 +6,11 @@ EXTRA_DIST = $(noinst_SCRIPTS) \
        bz2.vgperf \
        fbench.vgperf \
        ffbench.vgperf \
+       heap.vgperf \
        sarp.vgperf
 
 check_PROGRAMS = \
-       bigcode bz2 fbench ffbench sarp
+       bigcode bz2 fbench ffbench heap sarp
 
 AM_CFLAGS   = $(WERROR) -Winline -Wall -Wshadow -g -O
 AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/include
index 95192794667aaa03fbc89214c4fd41b9a3f04706..0dd8c16ccb7febf904e9ccc47e5922eec8c673cc 100644 (file)
@@ -13,6 +13,15 @@ bigcode1, bigcode2:
                of runtime, particularly on larger programs.
 - Weaknesses:  Highly artificial.
 
+heap:
+- Description: Does a lot of heap allocation and deallocation, and has a lot
+               of heap blocks live while doing so.
+- Strengths:   Stress test for an important sub-system; bug #105039 showed
+               that inefficiencies in heap allocation can make a big
+               difference to programs that allocate a lot.
+- Weaknesses:  Highly artificial -- allocation pattern is not real, and only
+               a few different size allocations are used.
+
 sarp:
 - Description: Does a lot of stack allocation and deallocation.
 - Strengths:   Tests for a specific performance bug that existed in 3.1.0 and
diff --git a/perf/heap.c b/perf/heap.c
new file mode 100644 (file)
index 0000000..c84f6cb
--- /dev/null
@@ -0,0 +1,39 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#define NLIVE 1000000
+
+#define NITERS (3*1000*1000)
+
+char* arr[NLIVE];
+
+int main ( void )
+{
+   int i, j, nbytes = 0;
+   printf("initialising\n");
+   for (i = 0; i < NLIVE; i++)
+      arr[i] = NULL;
+
+   printf("running\n");
+   j = -1;
+   for (i = 0; i < NITERS; i++) {
+      j++;
+      if (j == NLIVE) j = 0;
+      if (arr[j]) 
+         free(arr[j]);
+      arr[j] = malloc(nbytes);
+
+      // Cycle through the sizes 0,8,16,24,32.  Zero will get rounded up to
+      // 8, so the 8B bucket will get twice as much traffic.
+      nbytes += 8;
+      if (nbytes > 32)
+         nbytes = 0;
+   }
+
+   for (i = 0; i < NLIVE; i++)
+      if (arr[i])
+         free(arr[i]);
+
+   printf("done\n");
+   return 0;
+}
diff --git a/perf/heap.vgperf b/perf/heap.vgperf
new file mode 100644 (file)
index 0000000..a362801
--- /dev/null
@@ -0,0 +1,2 @@
+prog: heap
+tools: none memcheck
index 887cc96951cb93284c78e23171b08e38661fba54..565f112b1aae82c26c3c2c78b5f28a9bd8e34d06 100644 (file)
@@ -319,10 +319,10 @@ sub do_one_test($$)
             # the speedup.
             if (not defined $first_tTool{$tool}) {
                 $first_tTool{$tool} = $tTool;
-                print(" -----) ");
+                print(" -----)  ");
             } else {
                 my $speedup = 100 - (100 * $tTool / $first_tTool{$tool});
-                printf("%5.1f%%) ", $speedup);
+                printf("%5.1f%%)  ", $speedup);
             }
 
             $num_timings_done++;