Commit 44841540 authored by William Ahern's avatar William Ahern

make benchmark scripts a little easier to hack on

parent 954c0a82
...@@ -4,7 +4,7 @@ WHEEL_BIT = 6 ...@@ -4,7 +4,7 @@ WHEEL_BIT = 6
WHEEL_NUM = 4 WHEEL_NUM = 4
CPPFLAGS = -DTIMEOUT_DEBUG 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) timeout: CPPFLAGS+=-DWHEEL_BIT=$(WHEEL_BIT) -DWHEEL_NUM=$(WHEEL_NUM)
...@@ -31,16 +31,20 @@ bench: bench.c timeout.h ...@@ -31,16 +31,20 @@ bench: bench.c timeout.h
ifeq ($(shell uname -s), Darwin) ifeq ($(shell uname -s), Darwin)
SOFLAGS = -bundle -undefined dynamic_lookup SOFLAGS = -bundle -undefined dynamic_lookup
else else
SOFLAGS = -shared SOFLAGS = -fPIC -shared
endif endif
# so bench.so can load implementation module from CWD
LDFLAGS = -Wl,-rpath,.
# clock_gettime in librt.so
ifeq ($(shell uname -s), Linux) ifeq ($(shell uname -s), Linux)
LIBS = -lrt LIBS = -lrt
endif endif
bench.so: bench.c 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) bench-wheel8.so: CPPFLAGS+=-DWHEEL_BIT=3 -DWHEEL_NUM=$(WHEEL_NUM)
......
#!/usr/bin/env lua #!/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 limit = 1000000
local step = limit / 100 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 local n = limit
for i=0,limit,step do for i=0,limit,step do
bench:expire(n) -- expire all timeouts
local expire_t = aux.time(B.expire, B, n)
local start = clock() -- add i timeouts
bench:fill(i) local fill_t = aux.time(B.fill, B, i)
n = 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 end
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
#!/usr/bin/env lua #!/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 limit = 1000000
local step = limit / 100 local step = limit / 100
local bench = require"bench".new(lib, count)
local clock = require"bench".clock
for i=0,limit,step do local B = bench.new(lib, count)
bench:fill(i, 60 * 1000000)
local start = clock() for i=0,limit,step do
bench:del(0, i) local fill_t = aux.time(B.fill, B, i, 60 * 1000000)
local stop = clock() 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 end
#!/usr/bin/env lua #!/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 limit = 1000000
local step = limit / 100 local step = limit / 100
local bench = require"bench".new(lib, count)
local clock = require"bench".clock
for i=0,limit,step do local B = require"bench".new(lib, count)
bench:fill(i)
local start = clock() for i=0,limit,step do
bench:expire(i) local fill_t = aux.time(B.fill, B, i)
local stop = clock() 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 end
#include <stdlib.h> #include <stdlib.h>
#define TIMEOUT_PUBLIC static
#include "timeout.h" #include "timeout.h"
#include "timeout.c" #include "timeout.c"
#include "bench.h" #include "bench.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment