Skip to content

Commit 04728c3

Browse files
committed
add some tests
1 parent 29f8cfd commit 04728c3

File tree

3 files changed

+50
-3
lines changed

3 files changed

+50
-3
lines changed

test.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ local function main()
7777
local lclient = require 'lclient'
7878
local ws = require 'workspace'
7979

80-
log.print = true
80+
--log.print = true
8181

8282
---@async
8383
lclient():start(function (client)

test/full/init.lua

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,17 @@ require 'full.dirty'
2727
require 'full.projects'
2828
require 'full.self'
2929

30+
local times = {}
3031
for name, time in util.sortPairs(DIAGTIMES, function (k1, k2)
31-
return DIAGTIMES[k1] < DIAGTIMES[k2]
32+
return DIAGTIMES[k1] > DIAGTIMES[k2]
3233
end) do
33-
print('诊断任务耗时:', name, time)
34+
times[#times+1] = ('诊断任务耗时:%05.3f [%s]'):format(time, name)
35+
if #times >= 10 then
36+
break
37+
end
38+
end
39+
40+
util.revertTable(times)
41+
for _, time in ipairs(times) do
42+
print(time)
3443
end

test/full/self.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@ local diag = require 'provider.diagnostic'
55
local config = require 'config'
66
local ws = require 'workspace'
77
local guide = require 'parser.guide'
8+
local vm = require 'vm'
9+
local util = require 'utility'
810

911
local path = ROOT / 'script'
1012

1113
local uris = {}
1214

15+
files.reset()
1316
fsu.scanDirectory(path, function (path)
1417
if path:extension():string() ~= '.lua' then
1518
return
@@ -47,3 +50,38 @@ end
4750

4851
local passed = os.clock() - clock
4952
print('基准全量诊断用时:', passed)
53+
54+
vm.clearNodeCache()
55+
56+
local compileDatas = {}
57+
58+
for uri in files.eachFile() do
59+
local state = files.getState(uri)
60+
local clock = os.clock()
61+
guide.eachSource(state.ast, function (src)
62+
vm.compileNode(src)
63+
end)
64+
compileDatas[uri] = {
65+
passed = os.clock() - clock,
66+
uri = uri,
67+
}
68+
end
69+
70+
local printTexts = {}
71+
for uri, data in util.sortPairs(compileDatas, function (a, b)
72+
return compileDatas[a].passed > compileDatas[b].passed
73+
end) do
74+
printTexts[#printTexts+1] = ('全量编译耗时:%05.3f [%s]'):format(data.passed, uri)
75+
if #printTexts >= 10 then
76+
break
77+
end
78+
end
79+
80+
util.revertTable(printTexts)
81+
82+
for _, text in ipairs(printTexts) do
83+
print(text)
84+
end
85+
86+
local passed = os.clock() - clock
87+
print('基准全量编译用时:', passed)

0 commit comments

Comments
 (0)