forked from mailru/tntlua
-
Notifications
You must be signed in to change notification settings - Fork 1
/
benchmark.lua
48 lines (44 loc) · 965 Bytes
/
benchmark.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
--
-- simple Tarantool benchmarking framework
--
benchmark = {}
benchmark.tests = {}
benchmark.init = function()
local ffi = require("ffi")
ffi.cdef[[
typedef long time_t;
typedef struct timeval {
time_t tv_sec;
time_t tv_usec;
} timeval;
int gettimeofday(struct timeval *t, void *tzp);
]]
benchmark.now = function()
local t = ffi.new("timeval")
ffi.C.gettimeofday(t, nil)
return tonumber(t.tv_sec * 1000 + (t.tv_usec / 1000))
end
end
benchmark.add = function(name, f)
benchmark.tests[name] = f
end
benchmark.run = function(count)
print("Benchmarking (count: ", count, ")")
print("")
for name,func in pairs(benchmark.tests) do
print(">>> ", name)
local start = benchmark.now()
for key = 1,count do
func(key)
end
local diff = benchmark.now() - start
print("rps: ", count / (diff / 1000.0))
print("")
end
end
--
benchmark.init()
benchmark.add("insert", function(key)
box.insert(0, key)
end)
benchmark.run(10000000)