-
Notifications
You must be signed in to change notification settings - Fork 16
/
benchmark.lua
58 lines (47 loc) · 1.21 KB
/
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
49
50
51
52
53
54
55
56
57
58
--
-- benchmark.lua
-- Copyright (C) 2020 romgrk <romgrk@arch>
--
-- Distributed under terms of the MIT license.
--
local original = require'lua.original'
local native = require'lua.native'
local function lines_from(file)
lines = {}
for line in io.lines(file) do
lines[#lines + 1] = line
end
return lines
end
function benchmark(fn)
local total = 0
-- Warmup
for i = 1, 5 do
total = total + #fn()
end
local start = os.clock()
total = 0
for i = 1, 1 do
total = total + #fn()
end
local end_ = os.clock()
return (end_ - start) * 1000, total
end
function main()
local lines = lines_from('./tests/files.txt')
print('Lines: ' .. #lines)
print('')
local time, total = benchmark(function() return native.filter('f', lines) end)
print('Native:')
print(' -> Total: ' .. total)
print(' -> Time: ' .. time .. ' ms')
local time, total = benchmark(function() return native.filter_many('f', lines) end)
print('Native (many):')
print(' -> Total: ' .. total)
print(' -> Time: ' .. time .. ' ms')
local time, total = benchmark(function() return original.filter('f', lines) end)
print('Original:')
print(' -> Total: ' .. total)
print(' -> Time: ' .. time .. ' ms')
end
main()