1
1
#! /usr/bin/env tarantool
2
2
3
- require (' strict' ).on ()
4
- local tap = require (' tap' )
3
+ local t = require (' luatest' )
4
+
5
+ local checks = require (' checks' )
5
6
local json = require (' json' )
7
+ local log = require (' log' )
6
8
local uuid = require (' uuid' )
7
- local checks = require (' checks' )
8
- local test = tap .test (' performance_test' )
9
9
10
- local total_time = 0
11
- local total_iter = 0
10
+ local g = t .group (' checks_performance' )
12
11
13
12
local args = {
14
13
[' nil' ] = nil ,
@@ -23,59 +22,138 @@ local args = {
23
22
[' uuid_bin' ] = uuid .bin (),
24
23
}
25
24
26
- local function perftest (check , argtype )
27
- local fn = function (arg )
28
- checks (check )
29
- end
25
+ local cases = {
26
+ {
27
+ check = ' ?' ,
28
+ argtype = ' nil' ,
29
+ },
30
+ {
31
+ check = ' ?' ,
32
+ argtype = ' nil' ,
33
+ },
30
34
31
- local arg = args [argtype ]
35
+ {
36
+ check = ' string' ,
37
+ argtype = ' string' ,
38
+ },
32
39
33
- local cnt = 0
34
- local batch_size = 1000
35
- local stop
36
- local start = os.clock ()
37
- repeat
38
- for i = 1 , batch_size do
39
- fn (arg )
40
- end
41
- cnt = cnt + batch_size
42
- batch_size = math.floor (batch_size * 1.2 )
43
- stop = os.clock ()
44
- until stop - start > 1
40
+ {
41
+ check = ' ?string' ,
42
+ argtype = ' nil' ,
43
+ },
44
+ {
45
+ check = ' ?string' ,
46
+ argtype = ' string' ,
47
+ },
45
48
46
- local testname = string.format (' checks(%s) (%s)' , json .encode (check ), argtype )
47
- test :diag (string.format (" %-35s: %.2f calls/s" , testname , cnt / (stop - start ) ))
48
- end
49
+ {
50
+ check = ' number|string' ,
51
+ argtype = ' string' ,
52
+ },
53
+ {
54
+ check = ' number|string' ,
55
+ argtype = ' number' ,
56
+ },
49
57
50
- perftest (' ?' , ' nil' )
51
- perftest (' ?' , ' string' )
58
+ {
59
+ check = ' meta' ,
60
+ argtype = ' meta' ,
61
+ },
62
+ {
63
+ check = ' ?string|meta' ,
64
+ argtype = ' nil' ,
65
+ },
66
+ {
67
+ check = ' ?string|meta' ,
68
+ argtype = ' string' ,
69
+ },
70
+ {
71
+ check = ' ?string|meta' ,
72
+ argtype = ' meta' ,
73
+ },
52
74
53
- perftest (' string' , ' string' )
75
+ {
76
+ check = ' int64' ,
77
+ argtype = ' number' ,
78
+ },
79
+ {
80
+ check = ' int64' ,
81
+ argtype = ' int64' ,
82
+ },
83
+ {
84
+ check = ' int64' ,
85
+ argtype = ' uint64' ,
86
+ },
87
+ {
88
+ check = ' uint64' ,
89
+ argtype = ' number' ,
90
+ },
91
+ {
92
+ check = ' uint64' ,
93
+ argtype = ' int64' ,
94
+ },
95
+ {
96
+ check = ' uint64' ,
97
+ argtype = ' uint64' ,
98
+ },
54
99
55
- perftest (' ?string' , ' nil' )
56
- perftest (' ?string' , ' string' )
100
+ {
101
+ check = ' uuid' ,
102
+ argtype = ' uuid' ,
103
+ },
104
+ {
105
+ check = ' uuid_str' ,
106
+ argtype = ' uuid_str' ,
107
+ },
108
+ {
109
+ check = ' uuid_bin' ,
110
+ argtype = ' uuid_bin' ,
111
+ },
57
112
58
- perftest (' number|string' , ' string' )
59
- perftest (' number|string' , ' number' )
113
+ {
114
+ check = {x = ' ?' },
115
+ argtype = ' table' ,
116
+ },
117
+ {
118
+ check = {x = {y = ' ?' }},
119
+ argtype = ' table' ,
120
+ },
121
+ {
122
+ check = {x = {y = {z = ' ?' }}},
123
+ argtype = ' table' ,
124
+ },
125
+ {
126
+ check = {x = {y = {z = {t = ' ?' }}}},
127
+ argtype = ' table' ,
128
+ },
129
+ -- TODO checks({timeout = '?number'}) -- table checker
130
+ }
131
+
132
+ for _ , case in pairs (cases ) do
133
+ -- dots in test case name are not expected
134
+ local name = (' test_%s_%s' ):format (json .encode (case .check ), case .argtype ):gsub (' %.' , ' _' )
60
135
61
- perftest ( ' meta ' , ' meta ' )
62
- perftest ( ' ?string|meta ' , ' nil ' )
63
- perftest ( ' ?string|meta ' , ' string ' )
64
- perftest ( ' ?string|meta ' , ' meta ' )
136
+ g [ name ] = function ( _ )
137
+ local fn = function ( arg ) -- luacheck: no unused args
138
+ checks ( case . check )
139
+ end
65
140
66
- perftest (' int64' , ' number' )
67
- perftest (' int64' , ' int64' )
68
- perftest (' int64' , ' uint64' )
69
- perftest (' uint64' , ' number' )
70
- perftest (' uint64' , ' int64' )
71
- perftest (' uint64' , ' uint64' )
141
+ local arg = args [case .argtype ]
72
142
73
- perftest (' uuid' , ' uuid' )
74
- perftest (' uuid_str' , ' uuid_str' )
75
- perftest (' uuid_bin' , ' uuid_bin' )
143
+ local cnt = 0
144
+ local batch_size = 1000
145
+ local stop
146
+ local start = os.clock ()
147
+ repeat
148
+ for _ = 1 , batch_size do
149
+ fn (arg )
150
+ end
151
+ cnt = cnt + batch_size
152
+ batch_size = math.floor (batch_size * 1.2 )
153
+ stop = os.clock ()
154
+ until stop - start > 1
76
155
77
- perftest ({x = ' ?' }, ' table' )
78
- perftest ({x = {y = ' ?' }}, ' table' )
79
- perftest ({x = {y = {z = ' ?' }}}, ' table' )
80
- perftest ({x = {y = {z = {t = ' ?' }}}}, ' table' )
81
- -- TODO checks({timeout = '?number'}) -- table checker
156
+ local testline = string.format (' checks(%s) (%s)' , json .encode (case .check ), case .argtype )
157
+ log .info (" %-35s: %.2f calls/s" , testline , cnt / (stop - start ))
158
+ end
159
+ end
0 commit comments