aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua
diff options
context:
space:
mode:
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua')
-rw-r--r--LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua99
1 files changed, 0 insertions, 99 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua b/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua
deleted file mode 100644
index 0c9403e..0000000
--- a/LuaSL/testLua/yueliang-0.4.1/orig-5.0.3/test/bench_llex.lua
+++ /dev/null
@@ -1,99 +0,0 @@
1--[[--------------------------------------------------------------------
2
3 bench_llex.lua
4 Benchmark test for llex.lua
5 This file is part of Yueliang.
6
7 Copyright (c) 2006 Kein-Hong Man <khman@users.sf.net>
8 The COPYRIGHT file describes the conditions
9 under which this software may be distributed.
10
11 See the ChangeLog for more information.
12
13----------------------------------------------------------------------]]
14
15require("../lzio")
16require("../llex")
17luaX:init()
18
19------------------------------------------------------------------------
20-- load in a standard set of sample files
21-- * file set is 5.0.3 front end set sans luac.lua
22------------------------------------------------------------------------
23
24local fileset, totalsize = {}, 0
25for fn in string.gfind([[
26../lcode.lua
27../ldump.lua
28../llex.lua
29../lopcodes.lua
30../lparser.lua
31../lzio.lua
32]], "%S+") do
33 table.insert(fileset, fn)
34end
35
36for i = 1, table.getn(fileset) do
37 local fn = fileset[i]
38 local inf = io.open(fn, "rb")
39 if not inf then
40 error("failed to open "..fn.." for reading")
41 end
42 local data = inf:read("*a")
43 local data_sz = string.len(data)
44 inf:close()
45 if not data or data_sz == 0 then
46 error("failed to read data from "..fn.." or file is zero-length")
47 end
48 totalsize = totalsize + data_sz
49 fileset[i] = data
50end
51
52------------------------------------------------------------------------
53-- benchmark tester
54------------------------------------------------------------------------
55
56local DURATION = 5 -- how long the benchmark should run
57
58local L = {} -- LuaState
59local LS = {} -- LexState
60
61local time = os.time
62local lexedsize = 0
63local tnow, elapsed = time(), 0
64
65while time() == tnow do end -- wait for second to click over
66tnow = time()
67
68while true do
69 for i = 1, table.getn(fileset) do
70 ------------------------------------------------------------
71 local chunk = fileset[i]
72 local z = luaZ:init(luaZ:make_getS(chunk), nil, "=string")
73 luaX:setinput(L, LS, z, z.name)
74 while true do
75 LS.t.token = luaX:lex(LS, LS.t)
76 local tok, seminfo = LS.t.token, LS.t.seminfo
77 if tok == "TK_EOS" then break end
78 end
79 ------------------------------------------------------------
80 lexedsize = lexedsize + string.len(chunk)
81 if time() > tnow then
82 tnow = time()
83 elapsed = elapsed + 1
84 if elapsed >= DURATION then
85 -- report performance of lexer
86 lexedsize = lexedsize / 1024
87 local speed = lexedsize / DURATION
88 print("Lexer performance:")
89 print("Size of data lexed (KB): "..string.format("%.1f", lexedsize))
90 print("Speed of lexer (KB/s): "..string.format("%.1f", speed))
91 -- repeat until user breaks program
92 elapsed = 0
93 end
94 end
95 ------------------------------------------------------------
96 end--for
97end--while
98
99-- end of script