-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathperftest.lua
executable file
·79 lines (64 loc) · 2.11 KB
/
perftest.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env tarantool
require('strict').on()
local tap = require('tap')
local fio = require('fio')
local errors = require('errors')
local test = tap.test('performance_test')
box.cfg{
listen = '127.0.0.1:13301',
wal_mode = 'none',
work_dir = fio.tempdir(),
log_level = 0,
}
box.schema.user.grant('guest', 'super')
fio.rmtree(box.cfg.work_dir)
local function perftest(testname, fn, ...)
local cnt = 0
local batch_size = 1000
local stop
local start = os.clock()
repeat
for _ = 1, batch_size do
fn(...)
end
cnt = cnt + batch_size
batch_size = math.floor(batch_size * 1.2)
stop = os.clock()
until stop - start > 1
test:diag(string.format("%-35s: %.2f calls/s", testname, cnt/(stop-start) ))
end
local conn = require('net.box').connect(box.cfg.listen)
test:diag('Errors perftest')
test:diag('')
test:diag(' Wrap pcall')
local E = errors.new_class('E')
test:diag(' return true')
local function f() return true end
perftest(' - native pcall', pcall, f)
perftest(' - errors.pcall', errors.pcall, 'E', f)
perftest(' - E:pcall', E.pcall, E, f)
test:diag(' raise error')
local function f() error('Artificial error', 0) end
perftest(' - native pcall', pcall, f)
perftest(' - errors.pcall', errors.pcall, 'E', f)
perftest(' - E:pcall', E.pcall, E, f)
test:diag('')
test:diag(' Wrap netbox calls')
test:diag(' return true')
function _G.f() return 1 end
perftest(' - netbox', conn.call, conn, 'f')
perftest(' - errors', errors.netbox_call, conn, 'f')
test:diag(' return multiret')
function _G.f() return 1, nil, 2, nil, 3, nil end
perftest(' - netbox', conn.call, conn, 'f')
perftest(' - errors', errors.netbox_call, conn, 'f')
test:diag(' return nil, err')
local err = errors.new('TestError', 'Artificial error')
function _G.f() return nil, err end
perftest(' - netbox', conn.call, conn, 'f')
perftest(' - errors', errors.netbox_call, conn, 'f')
test:diag(' throw error')
function _G.f() error('Artificial error', 0) end
perftest(' - netbox', pcall, conn.call, conn, 'f')
perftest(' - errors', errors.netbox_call, conn, 'f')
os.exit(0)