Skip to content

Commit f813f36

Browse files
committed
add performance test for encoding messages
1 parent 594797f commit f813f36

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

perf/encode_perf.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env lua
2+
local frame = require'websocket.frame'
3+
local socket = require'socket'
4+
local encode = frame.encode
5+
local TEXT = frame.TEXT
6+
local s = string.rep('abc',100)
7+
8+
local tests = {
9+
['---WITH XOR---'] = true,
10+
['---WITHOUT XOR---'] = false
11+
}
12+
13+
for name,do_xor in pairs(tests) do
14+
print(name)
15+
local n = 1000000
16+
local t1 = socket.gettime()
17+
for i=1,100000 do
18+
encode(s,TEXT,do_xor)
19+
end
20+
local dt = socket.gettime() - t1
21+
print('n=',n)
22+
print('dt=',dt)
23+
print('ops/sec=',n/dt)
24+
print('microsec/op=',1000000*dt/n)
25+
end

0 commit comments

Comments
 (0)