Commit 954c0a82 authored by william's avatar william

add benchmark scripts

parent 273e79a5
#!/usr/bin/env lua
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 n = limit
for i=0,limit,step do
bench:expire(n)
local start = clock()
bench:fill(i)
n = i
local stop = clock()
print(i, math.floor((stop - start) * 1000000))
end
#!/usr/bin/env lua
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 start = clock()
bench:del(0, i)
local stop = clock()
print(i, math.floor((stop - start) * 1000000))
end
#!/usr/bin/env lua
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 start = clock()
bench:expire(i)
local stop = clock()
print(i, math.floor((stop - start) * 1000000))
end
...@@ -28,7 +28,6 @@ struct bench { ...@@ -28,7 +28,6 @@ struct bench {
struct timeout *timeout; struct timeout *timeout;
struct benchops ops; struct benchops ops;
timeout_t curtime; timeout_t curtime;
}; /* struct bench */ }; /* struct bench */
...@@ -36,21 +35,27 @@ struct bench { ...@@ -36,21 +35,27 @@ struct bench {
static mach_timebase_info_data_t timebase; static mach_timebase_info_data_t timebase;
#endif #endif
static int bench_clock(lua_State *L) {
static int long long monotime(void) {
#if __APPLE__ #if __APPLE__
unsigned long long abt; unsigned long long abt;
abt = mach_absolute_time(); abt = mach_absolute_time();
abt = abt * timebase.numer / timebase.denom; abt = abt * timebase.numer / timebase.denom;
lua_pushnumber(L, (double)abt / 1000000000L); return abt / 1000LL;
#else #else
struct timespec ts; struct timespec ts;
clock_gettime(CLOCK_MONOTONIC, &ts); clock_gettime(CLOCK_MONOTONIC, &ts);
lua_pushnumber(L, (double)ts.tv_sec + ((double)ts.tv_nsec / 1000000000L)); return (ts.tv_sec * 1000000L) + (ts.tv_nsec / 1000L);
#endif #endif
} /* monotime() */
static int bench_clock(lua_State *L) {
lua_pushnumber(L, (double)monotime() / 1000000L);
return 1; return 1;
} /* bench_clock() */ } /* bench_clock() */
...@@ -59,7 +64,7 @@ static int bench_clock(lua_State *L) { ...@@ -59,7 +64,7 @@ static int bench_clock(lua_State *L) {
static int bench_new(lua_State *L) { static int bench_new(lua_State *L) {
const char *path = luaL_checkstring(L, 1); const char *path = luaL_checkstring(L, 1);
size_t count = luaL_optlong(L, 2, 1000000); size_t count = luaL_optlong(L, 2, 1000000);
timeout_t tmax = luaL_optlong(L, 3, 60 * 1000); timeout_t tmax = luaL_optlong(L, 3, 300 * 1000000L);
int verbose = (lua_isnone(L, 4))? 0 : lua_toboolean(L, 4); int verbose = (lua_isnone(L, 4))? 0 : lua_toboolean(L, 4);
struct bench *B; struct bench *B;
struct benchops *ops; struct benchops *ops;
...@@ -106,11 +111,13 @@ static int bench_add(lua_State *L) { ...@@ -106,11 +111,13 @@ static int bench_add(lua_State *L) {
static int bench_del(lua_State *L) { static int bench_del(lua_State *L) {
struct bench *B = lua_touserdata(L, 1); struct bench *B = lua_touserdata(L, 1);
unsigned i; size_t i = luaL_optlong(L, 2, random() % B->count);
size_t j = luaL_optlong(L, 3, i);
i = (lua_isnoneornil(L, 2))? random() % B->count : (unsigned)luaL_checklong(L, 2); while (i <= j && i < B->count) {
B->ops.del(B->state, &B->timeout[i]);
B->ops.del(B->state, &B->timeout[i]); ++i;
}
return 0; return 0;
} /* bench_del() */ } /* bench_del() */
...@@ -119,10 +126,17 @@ static int bench_del(lua_State *L) { ...@@ -119,10 +126,17 @@ static int bench_del(lua_State *L) {
static int bench_fill(lua_State *L) { static int bench_fill(lua_State *L) {
struct bench *B = lua_touserdata(L, 1); struct bench *B = lua_touserdata(L, 1);
size_t count = luaL_optlong(L, 2, B->count); size_t count = luaL_optlong(L, 2, B->count);
long timeout = luaL_optlong(L, 3, -1);
size_t i; size_t i;
for (i = 0; i < count; i++) { if (timeout < 0) {
B->ops.add(B->state, &B->timeout[i], random() % B->maximum); for (i = 0; i < count; i++) {
B->ops.add(B->state, &B->timeout[i], random() % B->maximum);
}
} else {
for (i = 0; i < count; i++) {
B->ops.add(B->state, &B->timeout[i], timeout + i);
}
} }
return 0; return 0;
...@@ -132,7 +146,7 @@ static int bench_fill(lua_State *L) { ...@@ -132,7 +146,7 @@ static int bench_fill(lua_State *L) {
static int bench_expire(lua_State *L) { static int bench_expire(lua_State *L) {
struct bench *B = lua_touserdata(L, 1); struct bench *B = lua_touserdata(L, 1);
unsigned count = luaL_optlong(L, 2, B->count); unsigned count = luaL_optlong(L, 2, B->count);
unsigned step = luaL_optlong(L, 3, 300); unsigned step = luaL_optlong(L, 3, 300000);
size_t i = 0; size_t i = 0;
while (i < count && !B->ops.empty(B->state)) { while (i < count && !B->ops.empty(B->state)) {
......
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