-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathperformance.lua
56 lines (48 loc) · 1.48 KB
/
performance.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
local path = arg[1]
if not path then
print('No path!')
return
end
print('Input path = ' .. path)
local root = arg[0] .. '\\..\\..'
package.path = package.path .. ';' .. root .. '\\src\\?.lua'
.. ';' .. root .. '\\src\\?\\init.lua'
.. ';' .. root .. '\\test\\?.lua'
.. ';' .. root .. '\\test\\?\\init.lua'
local fs = require 'bee.filesystem'
local util = require 'utility'
local parser = require 'parser'
local function scanFiles(fspath, callback)
if fs.is_directory(fspath) then
for subpath in fs.pairs(fspath) do
scanFiles(subpath, callback)
end
else
callback(fspath)
end
end
print('Scanning files...')
local fileNames = {}
scanFiles(fs.path(path), function (fullPath)
if fullPath:extension():string() ~= '.lua' then
return
end
fileNames[#fileNames+1] = fullPath:string()
end)
print('Loading files...')
local files = {}
local size = 0
for _, fileName in ipairs(fileNames) do
local file = util.loadFile(fileName)
files[#files+1] = file
size = size + #file
end
print(('Loaded %d files, total size = %.3f KB'):format(#files, size / 1000))
print('Start parsing...')
local clock = os.clock()
for _, file in ipairs(files) do
local state = parser.compile(file, 'Lua', 'Lua 5.4')
parser.luadoc(state)
end
local passed = os.clock() - clock
print(('Total time = %.3f s, speed = %.3f MB/s'):format(passed, size / passed / 1000 / 1000))