Commit 8793dd42 authored by William Ahern's avatar William Ahern

more benchmark script work

parent 44841540
all: bench.so bench-wheel.so bench-heap.so
all: bench.so bench-wheel.so bench-heap.so bench-llrb.so
WHEEL_BIT = 6
WHEEL_NUM = 4
......
......@@ -3,22 +3,28 @@
local bench = require"bench"
local aux = require"bench-aux"
local lib = ... or "bench-wheel.so"
local limit = 1000000
local step = limit / 100
local lib = ... or aux.optenv("BENCH_L", "bench-wheel.so")
local limit = tonumber(aux.optenv("BENCH_N", 1000000))
local step = tonumber(aux.optenv("BENCH_S", limit / 100))
local exp_step = tonumber(aux.optenv("BENCH_E", 1.0))
local verbose = aux.toboolean(os.getenv("BENCH_V", false))
local B = bench.new(lib, count)
B:fill(limit)
local n = limit
local B = bench.new(lib, count, nil, verbose)
local fill_count, fill_last = B:fill(limit)
for i=0,limit,step do
local exp_elapsed, fill_elapsed, fill_rate
-- expire all timeouts
local expire_t = aux.time(B.expire, B, n)
--exp_elapsed = aux.time(B.expire, B, fill_count, fill_last * exp_step)
exp_elapsed = aux.time(B.del, B, 0, fill_count)
assert(B:empty())
-- add i timeouts
local fill_t = aux.time(B.fill, B, i)
n = i
fill_elapsed, fill_count, fill_last = aux.time(B.fill, B, i)
assert(fill_count == i)
fill_rate = fill_elapsed > 0 and (fill_count / fill_elapsed) or 0
aux.say("%i\t%f\t(%f)", i, fill_t, expire_t)
local fmt = verbose and "%d\t%f\t(%d/s)\t(exp:%f)" or "%d\t%f"
aux.say(fmt, i, fill_elapsed, fill_rate, exp_elapsed)
end
......@@ -17,4 +17,14 @@ function aux.say(...)
print(string.format(...))
end
function aux.toboolean(s)
return tostring(s):match("^[1TtYy]") and true or false
end
function aux.optenv(k, def)
local s = os.getenv(k)
return (s and #s > 0 and s) or def
end
return aux
......@@ -3,15 +3,23 @@
local bench = require"bench"
local aux = require"bench-aux"
local lib = ... or "bench-wheel.so"
local limit = 1000000
local step = limit / 100
local lib = ... or aux.optenv("BENCH_L", "bench-wheel.so")
local limit = tonumber(aux.optenv("BENCH_N", 1000000))
local step = tonumber(aux.optenv("BENCH_S", limit / 100))
local verbose = aux.toboolean(os.getenv("BENCH_V", false))
local B = bench.new(lib, count)
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)
-- add i timeouts
local fill_elapsed, fill_count = aux.time(B.fill, B, i, 60 * 1000000)
assert(i == fill_count)
aux.say("%i\t%f\t(%f)", i, del_t, fill_t)
--- delete i timeouts
local del_elapsed = aux.time(B.del, B, 0, fill_count)
assert(B:empty())
local del_rate = i > 0 and i / del_elapsed or 0
local fmt = verbose and "%d\t%f\t(%d/s)\t(fill:%f)" or "%d\t%f"
aux.say(fmt, i, del_elapsed, del_rate, fill_elapsed)
end
......@@ -3,15 +3,27 @@
local bench = require"bench"
local aux = require"bench-aux"
local lib = ... or "bench-wheel.so"
local limit = 1000000
local step = limit / 100
local lib = ... or aux.optenv("BENCH_L", "bench-wheel.so")
local limit = tonumber(aux.optenv("BENCH_N", 1000000))
local step = tonumber(aux.optenv("BENCH_S", limit / 100))
-- expire 1/1000 * #timeouts per clock update
local exp_step = tonumber(aux.optenv("BENCH_E", 0.0001))
local verbose = aux.toboolean(os.getenv("BENCH_V", false))
local B = require"bench".new(lib, count)
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)
-- add i timeouts
local fill_elapsed, fill_count, fill_last = aux.time(B.fill, B, i)
aux.say("%i\t%f\t(%f)", i, expire_t, fill_t)
-- expire timeouts by iteratively updating clock. exp_step is the
-- approximate number of timeouts (as a fraction of the total number
-- of timeouts) that will expire per update.
local exp_elapsed, exp_count = aux.time(B.expire, B, fill_count, fill_last * exp_step)
assert(exp_count == i)
assert(B:empty())
local exp_rate = i > 0 and i / exp_elapsed or 0
local fmt = verbose and "%d\t%f\t(%d/s)\t(fill:%f)" or "%d\t%f"
aux.say(fmt, i, exp_elapsed, exp_rate, fill_elapsed)
end
......@@ -16,12 +16,16 @@
#include "timeout.h"
#include "bench.h"
#ifndef MAX
#define MAX(a, b) (((a) > (b))? (a) : (b))
#endif
struct bench {
const char *path;
void *solib;
size_t count;
timeout_t maximum;
timeout_t timeout_max;
int verbose;
void *state;
......@@ -64,7 +68,7 @@ static int bench_clock(lua_State *L) {
static int bench_new(lua_State *L) {
const char *path = luaL_checkstring(L, 1);
size_t count = luaL_optlong(L, 2, 1000000);
timeout_t tmax = luaL_optlong(L, 3, 300 * 1000000L);
timeout_t timeout_max = luaL_optlong(L, 3, 300 * 1000000L);
int verbose = (lua_isnone(L, 4))? 0 : lua_toboolean(L, 4);
struct bench *B;
struct benchops *ops;
......@@ -76,7 +80,7 @@ static int bench_new(lua_State *L) {
lua_setmetatable(L, -2);
B->count = count;
B->maximum = tmax;
B->timeout_max = timeout_max;
B->verbose = verbose;
if (!(B->timeout = calloc(count, sizeof *B->timeout)))
......@@ -101,7 +105,7 @@ static int bench_add(lua_State *L) {
timeout_t t;
i = (lua_isnoneornil(L, 2))? random() % B->count : (unsigned)luaL_checklong(L, 2);
t = (lua_isnoneornil(L, 3))? random() % B->maximum : (unsigned)luaL_checklong(L, 3);
t = (lua_isnoneornil(L, 3))? random() % B->timeout_max : (unsigned)luaL_checklong(L, 3);
B->ops.add(B->state, &B->timeout[i], t);
......@@ -126,20 +130,27 @@ static int bench_del(lua_State *L) {
static int bench_fill(lua_State *L) {
struct bench *B = lua_touserdata(L, 1);
size_t count = luaL_optlong(L, 2, B->count);
long timeout = luaL_optlong(L, 3, -1);
long timeout_inc = luaL_optlong(L, 3, -1), timeout_max = 0, timeout;
size_t i;
if (timeout < 0) {
if (timeout_inc < 0) {
for (i = 0; i < count; i++) {
B->ops.add(B->state, &B->timeout[i], random() % B->maximum);
timeout = random() % B->timeout_max;
B->ops.add(B->state, &B->timeout[i], timeout);
timeout_max = MAX(timeout, timeout_max);
}
} else {
for (i = 0; i < count; i++) {
B->ops.add(B->state, &B->timeout[i], timeout + i);
timeout = timeout_inc + i;
B->ops.add(B->state, &B->timeout[i], timeout_inc + i);
timeout_max = MAX(timeout, timeout_max);
}
}
return 0;
lua_pushinteger(L, (lua_Integer)count);
lua_pushinteger(L, (lua_Integer)timeout_max);
return 2;
} /* bench_fill() */
......@@ -157,10 +168,21 @@ static int bench_expire(lua_State *L) {
i++;
}
return 0;
lua_pushinteger(L, (lua_Integer)i);
return 1;
} /* bench_expire() */
static int bench_empty(lua_State *L) {
struct bench *B = lua_touserdata(L, 1);
lua_pushboolean(L, B->ops.empty(B->state));
return 1;
} /* bench_empty() */
static int bench__gc(lua_State *L) {
struct bench *B = lua_touserdata(L, 1);
......@@ -178,6 +200,7 @@ static const luaL_Reg bench_methods[] = {
{ "del", &bench_del },
{ "fill", &bench_fill },
{ "expire", &bench_expire },
{ "empty", &bench_empty },
{ "close", &bench__gc },
{ NULL, NULL }
};
......
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