diff options
| author | William Ahern <[email protected]> | 2016-02-22 14:19:21 -0800 |
|---|---|---|
| committer | William Ahern <[email protected]> | 2016-02-22 14:19:21 -0800 |
| commit | 44841540be96a0dc8ddb36bc328222285990beb7 (patch) | |
| tree | 88d8f6d319a3cd80e342dc0578312cf74d5131d4 | |
| parent | 954c0a82845fdacc8c4423430af44d5169f4e3f6 (diff) | |
make benchmark scripts a little easier to hack on
| -rw-r--r-- | Makefile | 10 | ||||
| -rw-r--r-- | bench-add.lua | 21 | ||||
| -rw-r--r-- | bench-aux.lua | 20 | ||||
| -rw-r--r-- | bench-del.lua | 18 | ||||
| -rw-r--r-- | bench-expire.lua | 18 | ||||
| -rw-r--r-- | bench-wheel.c | 2 |
6 files changed, 56 insertions, 33 deletions
@@ -4,7 +4,7 @@ WHEEL_BIT = 6 WHEEL_NUM = 4 CPPFLAGS = -DTIMEOUT_DEBUG -CFLAGS = -O2 -g -Wall -Wextra -Wno-unused-parameter +CFLAGS = -O2 -march=native -g -Wall -Wextra -Wno-unused-parameter timeout: CPPFLAGS+=-DWHEEL_BIT=$(WHEEL_BIT) -DWHEEL_NUM=$(WHEEL_NUM) @@ -31,16 +31,20 @@ bench: bench.c timeout.h ifeq ($(shell uname -s), Darwin) SOFLAGS = -bundle -undefined dynamic_lookup else -SOFLAGS = -shared +SOFLAGS = -fPIC -shared endif +# so bench.so can load implementation module from CWD +LDFLAGS = -Wl,-rpath,. + +# clock_gettime in librt.so ifeq ($(shell uname -s), Linux) LIBS = -lrt endif bench.so: bench.c - $(CC) -o $@ $< $(CPPFLAGS) -DLUA_COMPAT_ALL $(CFLAGS) -Wno-unused-function $(SOFLAGS) $(LIBS) + $(CC) -o $@ $< $(CPPFLAGS) -DLUA_COMPAT_ALL $(CFLAGS) -Wno-unused-function $(SOFLAGS) $(LDFLAGS) $(LIBS) bench-wheel8.so: CPPFLAGS+=-DWHEEL_BIT=3 -DWHEEL_NUM=$(WHEEL_NUM) diff --git a/bench-add.lua b/bench-add.lua index 9227342..ce2989f 100644 --- a/bench-add.lua +++ b/bench-add.lua @@ -1,23 +1,24 @@ #!/usr/bin/env lua -local lib = ... or "bench-wheel.so" +local bench = require"bench" +local aux = require"bench-aux" +local lib = ... or "bench-wheel.so" local limit = 1000000 local step = limit / 100 -local bench = require"bench".new(lib, count) -local clock = require"bench".clock -bench:fill(limit) +local B = bench.new(lib, count) + +B:fill(limit) local n = limit for i=0,limit,step do - bench:expire(n) + -- expire all timeouts + local expire_t = aux.time(B.expire, B, n) - local start = clock() - bench:fill(i) + -- add i timeouts + local fill_t = aux.time(B.fill, B, i) n = i - local stop = clock() - print(i, math.floor((stop - start) * 1000000)) + aux.say("%i\t%f\t(%f)", i, fill_t, expire_t) end - diff --git a/bench-aux.lua b/bench-aux.lua new file mode 100644 index 0000000..9a8ea4a --- /dev/null +++ b/bench-aux.lua @@ -0,0 +1,20 @@ +local bench = require"bench" +local clock = bench.clock + +local aux = {} + +local function time_return(begun, ...) + local duration = clock() - begun + return duration, ... +end + +function aux.time(f, ...) + local begun = clock() + return time_return(begun, f(...)) +end + +function aux.say(...) + print(string.format(...)) +end + +return aux diff --git a/bench-del.lua b/bench-del.lua index fd0936f..4a3442b 100644 --- a/bench-del.lua +++ b/bench-del.lua @@ -1,19 +1,17 @@ #!/usr/bin/env lua -local lib = ... or "bench-wheel.so" +local bench = require"bench" +local aux = require"bench-aux" +local lib = ... or "bench-wheel.so" local limit = 1000000 local step = limit / 100 -local bench = require"bench".new(lib, count) -local clock = require"bench".clock -for i=0,limit,step do - bench:fill(i, 60 * 1000000) +local B = bench.new(lib, count) - local start = clock() - bench:del(0, i) - local stop = clock() +for i=0,limit,step do + local fill_t = aux.time(B.fill, B, i, 60 * 1000000) + local del_t = aux.time(B.del, B, 0, i) - print(i, math.floor((stop - start) * 1000000)) + aux.say("%i\t%f\t(%f)", i, del_t, fill_t) end - diff --git a/bench-expire.lua b/bench-expire.lua index ee4ace6..ff3e9e3 100644 --- a/bench-expire.lua +++ b/bench-expire.lua @@ -1,19 +1,17 @@ #!/usr/bin/env lua -local lib = ... or "bench-wheel.so" +local bench = require"bench" +local aux = require"bench-aux" +local lib = ... or "bench-wheel.so" local limit = 1000000 local step = limit / 100 -local bench = require"bench".new(lib, count) -local clock = require"bench".clock -for i=0,limit,step do - bench:fill(i) +local B = require"bench".new(lib, count) - local start = clock() - bench:expire(i) - local stop = clock() +for i=0,limit,step do + local fill_t = aux.time(B.fill, B, i) + local expire_t = aux.time(B.expire, B, i)--, 60000000) - print(i, math.floor((stop - start) * 1000000)) + aux.say("%i\t%f\t(%f)", i, expire_t, fill_t) end - diff --git a/bench-wheel.c b/bench-wheel.c index deff882..3089140 100644 --- a/bench-wheel.c +++ b/bench-wheel.c @@ -1,5 +1,7 @@ #include <stdlib.h> +#define TIMEOUT_PUBLIC static + #include "timeout.h" #include "timeout.c" #include "bench.h" |
