-
Notifications
You must be signed in to change notification settings - Fork 35
/
bench.cpp
61 lines (53 loc) · 1.88 KB
/
bench.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <memory>
#include <unistd.h>
#include "./src/core.h"
#include "./src/fs.h"
#include "./src/parser2.h"
#include "./src/checker/vm2.h"
#include "./src/checker/module2.h"
#include "./src/checker/debug.h"
#include "./src/checker/compiler.h"
using namespace tr;
void compileAndRun(const string &code, const string &fileName) {
ZoneScoped;
auto iterations = 1000;
auto cold = benchRun(iterations, [&] {
checker::Compiler compiler;
Parser parser;
auto result = parser.parseSourceFile(fileName, code, types::ScriptTarget::Latest, false, ScriptKind::TS, {});
auto program = compiler.compileSourceFile(result);
auto bin = program.build();
auto module = make_shared<vm2::Module>(bin, fileName, code);
vm2::run(module);
});
checker::Compiler compiler;
Parser parser;
auto result = parser.parseSourceFile(fileName, code, types::ScriptTarget::Latest, false, ScriptKind::TS, {});
auto program = compiler.compileSourceFile(result);
auto bin = program.build();
auto module = make_shared<vm2::Module>(bin, fileName, code);
auto warm = benchRun(iterations, [&] {
module->clear();
vm2::run(module);
});
std::cout << fmt::format("typerunner: {} iterations (it): cold {:.9f}ms/it, warm {:.9f}ms/it\n", iterations, cold.count() / iterations, warm.count() / iterations);
}
int main(int argc, char *argv[]) {
ZoneScoped;
std::string file;
auto cwd = std::filesystem::current_path();
if (argc > 1) {
file = cwd.string() + "/" + argv[1];
} else {
file = cwd.string() + "/../tests/basic1.ts";
}
if (!fileExists(file)) {
std::cout << "File not found " << file << "\n";
return 4;
}
auto code = fileRead(file);
auto relative = std::filesystem::relative(file, cwd);
compileAndRun(code, relative.string());
return 0;
}