summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2013-02-19 12:02:20 +0100
committerYorhel <git@yorhel.nl>2013-02-19 13:05:58 +0100
commit3f1e48f2e00480fdb59a2cc095ba60fd107cdf6c (patch)
treebf148ab4060e6f4fe93fb77be9df418a2a181f9a
parent47e7cfd9ede09b7f6c1f0872098ab10e7692e71e (diff)
evtp: Benchmark bug fix + added benchmark with some actual load
The fix is what I actually intended the benchmark to do. I re-ran the benchmark on the previous commits, and my earlier conclusions on the performance are still mostly valid. Also added a 'WORK' option to see what happens under load. Here are the benchmark results on my PC (gcc 4.7.2 on Linux 3.7.8-1-ARCH x86_64). Compiled with -DNDEBUG -O3 and run three times: Without -DWORK: Orig: real 0m2.204s 0m2.200s 0m2.242s user 0m1.230s 0m1.200s 0m1.150s sys 0m2.420s 0m2.487s 0m2.597s Without atomics: real 0m2.227s 0m2.235s 0m2.222s user 0m1.223s 0m1.207s 0m1.190s sys 0m2.523s 0m2.540s 0m2.480s Merged locks when queueing done_func: real 0m1.569s 0m1.552s 0m1.543s user 0m1.157s 0m1.157s 0m1.190s sys 0m1.677s 0m1.613s 0m1.597s With -DWORK: Orig: real 0m1.325s 0m1.342s 0m1.329s user 0m1.650s 0m1.740s 0m1.660s sys 0m0.403s 0m0.313s 0m0.400s Without atomics: real 0m1.316s 0m1.342s 0m1.329s user 0m1.680s 0m1.670s 0m1.700s sys 0m0.373s 0m0.390s 0m0.363s Merged locks when queueing done_func: real 0m1.391s 0m1.424s 0m1.407s user 0m1.730s 0m1.693s 0m1.653s sys 0m0.317s 0m0.350s 0m0.397s With -DWORK the differences are rather minimal, which is to be expected since most of the time is spent in the actual work. It is still visible that with work, the lock merging clearly degrades performance a bit. (Also interesting to see that without -DWORK, the removal of the atomics slightly degrade performance. My earlier benchmarks gave the opposite results. I'm guessing that differences as small as these just aren't very reliably measurable. Luckily my "optimizations" were also simplifications, so they were worth doing regardless.)
-rw-r--r--test/Makefile14
-rw-r--r--test/evtp.c33
2 files changed, 33 insertions, 14 deletions
diff --git a/test/Makefile b/test/Makefile
index ab8c360..54fe952 100644
--- a/test/Makefile
+++ b/test/Makefile
@@ -23,12 +23,16 @@ test: yuri ecbuf evtp
ecbuf-bench: ../ecbuf.h ecbuf-bench.c
$(CC) $(CFLAGS) -DNDEBUG -I.. ecbuf-bench.c -o ecbuf-bench
-evtp-bench: ../evtp.c ../evtp.h evtp.c
- $(CC) $(CFLAGS) -DNDEBUG -DBENCH -I.. ../evtp.c evtp.c -lpthread -lev -o evtp-bench
+evtp-bench-plain: ../evtp.c ../evtp.h evtp.c
+ $(CC) $(CFLAGS) -DNDEBUG -DBENCH -I.. ../evtp.c evtp.c -lpthread -lm -lev -o evtp-bench-plain
-bench: ecbuf-bench evtp-bench
+evtp-bench-work: ../evtp.c ../evtp.h evtp.c
+ $(CC) $(CFLAGS) -DNDEBUG -DBENCH -DWORK -I.. ../evtp.c evtp.c -lpthread -lm -lev -o evtp-bench-work
+
+bench: ecbuf-bench evtp-bench-plain evtp-bench-work
./ecbuf-bench
- time ./evtp-bench
+ sh -c 'time ./evtp-bench-plain'
+ sh -c 'time ./evtp-bench-work'
clean:
- rm -f yuri ecbuf evtp ecbuf-bench evtp-bench
+ rm -f yuri ecbuf evtp ecbuf-bench evtp-benchp-lain evtp-bench-work
diff --git a/test/evtp.c b/test/evtp.c
index b9813c1..4c5f0d6 100644
--- a/test/evtp.c
+++ b/test/evtp.c
@@ -24,12 +24,17 @@
#error These tests should not be compiled with -DNDEBUG!
#endif
-#define BENCH_LOOPS 100000
+#ifdef WORK
+#define BENCH_LOOPS 2000
+#else
+#define BENCH_LOOPS 50000
+#endif
#include "evtp.h"
#include <assert.h>
#include <stdlib.h>
#include <string.h>
+#include <math.h>
static evtp_t *tp;
static char data[51];
@@ -58,14 +63,16 @@ static void done_cb(evtp_work_t *w) {
}
#ifdef BENCH
- loops++;
- if(loops < BENCH_LOOPS) {
- done = 0;
- memset(data, 0, sizeof(data));
- w = calloc(1, sizeof(evtp_work_t));
- w->data = data;
- evtp_submit(w, tp, work_cb, done_cb);
- return;
+ if(done == 50) {
+ loops++;
+ if(loops < BENCH_LOOPS) {
+ done = 0;
+ memset(data, 0, sizeof(data));
+ w = calloc(1, sizeof(evtp_work_t));
+ w->data = data;
+ evtp_submit(w, tp, work_cb, done_cb);
+ return;
+ }
}
#endif
@@ -78,7 +85,15 @@ static void done_cb(evtp_work_t *w) {
static void work_cb(evtp_work_t *w) {
char *d = w->data;
assert(*d == 0);
+#ifndef WORK
*d = 1;
+#else
+ double x = (double)(((char *)w->data)-data);
+ int i;
+ for(i = 0; i<100; i++)
+ x = cos(x);
+ *d = x > -10.0; /* Always true, but I hope that the compiler doesn't know that */
+#endif
}