-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.cpp
45 lines (34 loc) · 974 Bytes
/
benchmark.cpp
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
#include <chrono>
#include <iostream>
#include "evaluator.hpp"
#include "parser.hpp"
int main() {
std::string input = R"(
let fibonacci = fn(x) {
if (x == 0) {
return 0;
} else {
if (x == 1) {
return 1;
} else {
fibonacci(x - 1) + fibonacci(x - 2);
}
}
};
fibonacci(35);
)";
auto l = Lexer(input);
auto p = Parser(std::move(l));
auto program = p.parse_program();
auto env = new_environment();
using std::chrono::high_resolution_clock;
using std::chrono::duration;
using std::chrono::milliseconds;
auto t1 = high_resolution_clock::now();
// Execute benchmark run
auto result = eval(program, env);
auto t2 = high_resolution_clock::now();
duration<double, std::milli> benchmark_time = t2 - t1;
std::cout << "engine=eval, result=" << result->inspect() << ", duration=" << benchmark_time.count() / 1000 << std::endl;
return EXIT_SUCCESS;
}