Added a stress test which measures the cost of translation.
git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5341 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/perf/Makefile.am b/perf/Makefile.am
index e31c165..d6898bf 100644
--- a/perf/Makefile.am
+++ b/perf/Makefile.am
@@ -2,13 +2,14 @@
noinst_SCRIPTS = vg_perf
EXTRA_DIST = $(noinst_SCRIPTS) \
+ bigcode.vgperf \
bz2.vgperf \
fbench.vgperf \
ffbench.vgperf \
sarp.vgperf
check_PROGRAMS = \
- bz2 fbench ffbench sarp
+ bigcode bz2 fbench ffbench sarp
AM_CFLAGS = $(WERROR) -Winline -Wall -Wshadow -g -O
AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/include -I$(top_builddir)/include
diff --git a/perf/README b/perf/README
index f0754e9..9519279 100644
--- a/perf/README
+++ b/perf/README
@@ -1,9 +1,27 @@
------------------------------------------------------------------------------
+=============================================================================
Notes about performance benchmarks
------------------------------------------------------------------------------
-For each benchmark, here is a brief description and notes about strengths
-and weaknesses of the benchmark.
+=============================================================================
+For each benchmark, here is a brief description and notes about its
+strengths and weaknesses.
+-----------------------------------------------------------------------------
+Artificial stress tests
+-----------------------------------------------------------------------------
+bigcode1, bigcode2:
+- Description: Executes a lot of (nonsensical) code.
+- Strengths: Demonstrates the cost of translation which is a large part
+ of runtime, particularly on larger programs.
+- Weaknesses: Highly artificial.
+
+sarp:
+- Description: Does a lot of stack allocation and deallocation.
+- Strengths: Tests for a specific performance bug that existed in 3.1.0 and
+ all earlier versions.
+- Weaknesses: Highly artificial.
+
+-----------------------------------------------------------------------------
+Real programs
+-----------------------------------------------------------------------------
bz2:
- Description: Burrows-Wheeler compression and decompression.
- Strengths: A real, widely used program, very similar to the 256.bzip2
@@ -26,9 +44,4 @@
- Weaknesses: Dominated by the inner loop, which is quite long and flatters
Valgrind due to the small dispatcher overhead.
-sarp:
-- Description: Does a lot of stack allocation and deallocation.
-- Strengths: Tests for a specific performance bug that existed in 3.1.0 and
- all earlier versions.
-- Weaknesses: Highly artificial.
diff --git a/perf/bigcode.c b/perf/bigcode.c
new file mode 100644
index 0000000..0f444e0
--- /dev/null
+++ b/perf/bigcode.c
@@ -0,0 +1,73 @@
+// This artificial program runs a lot of code. The exact amount depends on
+// the command line -- if any command line args are given, it does exactly
+// the same amount of work, but using four times as much code.
+//
+// It's a stress test for Valgrind's translation speed; natively the two
+// modes run in about the same time (the I-cache effects aren't big enough
+// to make a difference), but under Valgrind the one running more code is
+// significantly slower due to the extra translation time.
+
+#include <stdio.h>
+#include <string.h>
+
+#define FN_SIZE 996 // Must be big enough to hold the compiled f()
+#define N_LOOPS 20000 // Should be divisible by four
+#define RATIO 4 // Ratio of code sizes between the two modes
+
+int f(int x, int y)
+{
+ int i;
+ for (i = 0; i < 5000; i++) {
+ switch (x % 8) {
+ case 1: y += 3;
+ case 2: y += x;
+ case 3: y *= 2;
+ default: y--;
+ }
+ }
+ return y;
+}
+
+static char a[FN_SIZE * N_LOOPS];
+
+int main(int argc, char* argv[])
+{
+ int h, i, sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
+ int n_fns, n_reps;
+
+ if (argc <= 1) {
+ // Mode 1: not so much code
+ n_fns = N_LOOPS / RATIO;
+ n_reps = RATIO;
+ printf("mode 1: ");
+ } else {
+ // Mode 2: lots of code
+ n_fns = N_LOOPS;
+ n_reps = 1;
+ printf("mode 1: ");
+ }
+ printf("%d copies of f(), %d reps\n", n_fns, n_reps);
+
+ // Make a whole lot of copies of f(). FN_SIZE is much bigger than f()
+ // will ever be (we hope).
+ for (i = 0; i < n_fns; i++) {
+ memcpy(&a[FN_SIZE*i], f, FN_SIZE);
+ }
+
+ for (h = 0; h < n_reps; h += 1) {
+ for (i = 0; i < n_fns; i += 4) {
+ int(*f1)(int,int) = (void*)&a[FN_SIZE*(i+0)];
+ int(*f2)(int,int) = (void*)&a[FN_SIZE*(i+1)];
+ int(*f3)(int,int) = (void*)&a[FN_SIZE*(i+2)];
+ int(*f4)(int,int) = (void*)&a[FN_SIZE*(i+3)];
+ sum1 += f1(i+0, n_fns-i+0);
+ sum2 += f2(i+1, n_fns-i+1);
+ sum3 += f3(i+2, n_fns-i+2);
+ sum4 += f4(i+3, n_fns-i+3);
+ if (i % 1000 == 0)
+ printf(".");
+ }
+ }
+ printf("result = %d\n", sum1 + sum2 + sum3 + sum4);
+ return 0;
+}
diff --git a/perf/bigcode1.vgperf b/perf/bigcode1.vgperf
new file mode 100644
index 0000000..1f39f38
--- /dev/null
+++ b/perf/bigcode1.vgperf
@@ -0,0 +1,2 @@
+prog: bigcode
+tools: none memcheck
diff --git a/perf/bigcode2.vgperf b/perf/bigcode2.vgperf
new file mode 100644
index 0000000..a7fc954
--- /dev/null
+++ b/perf/bigcode2.vgperf
@@ -0,0 +1,3 @@
+prog: bigcode
+args: 0
+tools: none memcheck