diff options
Diffstat (limited to 'LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua')
-rw-r--r-- | LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua new file mode 100644 index 0000000..6b2a4a6 --- /dev/null +++ b/LuaSL/testLua/yueliang-0.4.1/nat-5.0.3/test/bench_llex_mk3.lua | |||
@@ -0,0 +1,92 @@ | |||
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 | |||
15 | local lex_init = require("../llex_mk3") | ||
16 | |||
17 | ------------------------------------------------------------------------ | ||
18 | -- load in a standard set of sample files | ||
19 | -- * file set is 5.0.3 front end set sans luac.lua | ||
20 | ------------------------------------------------------------------------ | ||
21 | |||
22 | local fileset, totalsize = {}, 0 | ||
23 | for fn in string.gfind([[ | ||
24 | ../../orig-5.0.3/lcode.lua | ||
25 | ../../orig-5.0.3/ldump.lua | ||
26 | ../../orig-5.0.3/llex.lua | ||
27 | ../../orig-5.0.3/lopcodes.lua | ||
28 | ../../orig-5.0.3/lparser.lua | ||
29 | ../../orig-5.0.3/lzio.lua | ||
30 | ]], "%S+") do | ||
31 | table.insert(fileset, fn) | ||
32 | end | ||
33 | |||
34 | for i = 1, table.getn(fileset) do | ||
35 | local fn = fileset[i] | ||
36 | local inf = io.open(fn, "rb") | ||
37 | if not inf then | ||
38 | error("failed to open "..fn.." for reading") | ||
39 | end | ||
40 | local data = inf:read("*a") | ||
41 | local data_sz = string.len(data) | ||
42 | inf:close() | ||
43 | if not data or data_sz == 0 then | ||
44 | error("failed to read data from "..fn.." or file is zero-length") | ||
45 | end | ||
46 | totalsize = totalsize + data_sz | ||
47 | fileset[i] = data | ||
48 | end | ||
49 | |||
50 | ------------------------------------------------------------------------ | ||
51 | -- benchmark tester | ||
52 | ------------------------------------------------------------------------ | ||
53 | |||
54 | local DURATION = 5 -- how long the benchmark should run | ||
55 | |||
56 | local time = os.time | ||
57 | local lexedsize = 0 | ||
58 | local tnow, elapsed = time(), 0 | ||
59 | |||
60 | while time() == tnow do end -- wait for second to click over | ||
61 | tnow = time() | ||
62 | |||
63 | while true do | ||
64 | for i = 1, table.getn(fileset) do | ||
65 | ------------------------------------------------------------ | ||
66 | local chunk = fileset[i] | ||
67 | local luaX = lex_init(chunk, "=string") | ||
68 | while true do | ||
69 | local tok, seminfo = luaX:lex() | ||
70 | if tok == "<eof>" then break end | ||
71 | end | ||
72 | ------------------------------------------------------------ | ||
73 | lexedsize = lexedsize + string.len(chunk) | ||
74 | if time() > tnow then | ||
75 | tnow = time() | ||
76 | elapsed = elapsed + 1 | ||
77 | if elapsed >= DURATION then | ||
78 | -- report performance of lexer | ||
79 | lexedsize = lexedsize / 1024 | ||
80 | local speed = lexedsize / DURATION | ||
81 | print("Lexer performance:") | ||
82 | print("Size of data lexed (KB): "..string.format("%.1f", lexedsize)) | ||
83 | print("Speed of lexer (KB/s): "..string.format("%.1f", speed)) | ||
84 | -- repeat until user breaks program | ||
85 | elapsed = 0 | ||
86 | end | ||
87 | end | ||
88 | ------------------------------------------------------------ | ||
89 | end--for | ||
90 | end--while | ||
91 | |||
92 | -- end of script | ||