-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmarks.lua
More file actions
34 lines (30 loc) · 769 Bytes
/
benchmarks.lua
File metadata and controls
34 lines (30 loc) · 769 Bytes
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
require("eval")
require("lexer")
require("parser")
local function measure(body)
local startTime = os.time()
local result = body()
local endTime = os.time()
local diff = os.difftime(endTime, startTime)
print(string.format("%s, duration=%s", result, diff))
end
local function fastInput(size)
return string.format(
[[let fibonacci = fn(x) {
if (x < 2) {
return x;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
};
fibonacci(%s);]], size
)
end
local function parse(input)
local lexer = Lexer { input = input }
local parser = Parser { lexer = lexer }
return parser:parseProgram()
end
measure(function()
return Eval(parse(fastInput(35)), Environment {})
end)