summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwilliam <[email protected]>2014-02-02 20:43:08 -0800
committerwilliam <[email protected]>2014-02-02 20:43:08 -0800
commit954c0a82845fdacc8c4423430af44d5169f4e3f6 (patch)
tree46e7485c7aaa27e37798442f4957b5442a9f2f1f
parent273e79a56d362e408d8cdf3f23cc72fa592ab5aa (diff)
add benchmark scripts
-rw-r--r--bench-add.lua23
-rw-r--r--bench-del.lua19
-rw-r--r--bench-expire.lua19
-rw-r--r--bench.c38
4 files changed, 87 insertions, 12 deletions
diff --git a/bench-add.lua b/bench-add.lua
new file mode 100644
index 0000000..9227342
--- /dev/null
+++ b/bench-add.lua
@@ -0,0 +1,23 @@
+#!/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
+
diff --git a/bench-del.lua b/bench-del.lua
new file mode 100644
index 0000000..fd0936f
--- /dev/null
+++ b/bench-del.lua
@@ -0,0 +1,19 @@
+#!/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
+
diff --git a/bench-expire.lua b/bench-expire.lua
new file mode 100644
index 0000000..ee4ace6
--- /dev/null
+++ b/bench-expire.lua
@@ -0,0 +1,19 @@
+#!/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
+
diff --git a/bench.c b/bench.c
index f061b00..6ada220 100644
--- a/bench.c
+++ b/bench.c
@@ -28,7 +28,6 @@ struct bench {
struct timeout *timeout;
struct benchops ops;
timeout_t curtime;
-
}; /* struct bench */
@@ -36,21 +35,27 @@ struct bench {
static mach_timebase_info_data_t timebase;
#endif
-static int bench_clock(lua_State *L) {
+
+static int long long monotime(void) {
#if __APPLE__
unsigned long long abt;
abt = mach_absolute_time();
abt = abt * timebase.numer / timebase.denom;
- lua_pushnumber(L, (double)abt / 1000000000L);
+ return abt / 1000LL;
#else
struct timespec 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
+} /* monotime() */
+
+
+static int bench_clock(lua_State *L) {
+ lua_pushnumber(L, (double)monotime() / 1000000L);
return 1;
} /* bench_clock() */
@@ -59,7 +64,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, 60 * 1000);
+ timeout_t tmax = luaL_optlong(L, 3, 300 * 1000000L);
int verbose = (lua_isnone(L, 4))? 0 : lua_toboolean(L, 4);
struct bench *B;
struct benchops *ops;
@@ -106,11 +111,13 @@ static int bench_add(lua_State *L) {
static int bench_del(lua_State *L) {
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);
-
- B->ops.del(B->state, &B->timeout[i]);
+ while (i <= j && i < B->count) {
+ B->ops.del(B->state, &B->timeout[i]);
+ ++i;
+ }
return 0;
} /* bench_del() */
@@ -119,10 +126,17 @@ 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);
size_t i;
- for (i = 0; i < count; i++) {
- B->ops.add(B->state, &B->timeout[i], random() % B->maximum);
+ if (timeout < 0) {
+ 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;
@@ -132,7 +146,7 @@ static int bench_fill(lua_State *L) {
static int bench_expire(lua_State *L) {
struct bench *B = lua_touserdata(L, 1);
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;
while (i < count && !B->ops.empty(B->state)) {