forked from drspro/metta-wam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.js
105 lines (95 loc) · 2.66 KB
/
benchmark.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var fs = require("fs");
var exec_sync = require("child_process").execSync;
var SMALL = false;
var langs = {
HVM: {
tids: [1, 2, 4, 8],
tasks: {
"sort/bubble": [0, 64],
"sort/bitonic": [20, 24],
"sort/quick": [20, 24],
"sort/radix": [20, 24],
"lambda/arithmetic": [0, 120],
},
build: (task) => {
exec("cp ../../examples/"+task+"/main.hvm main.hvm");
exec("hvm compile main.hvm");
exec("cd main; cargo build --release; mv target/release/main ../main.bin");
},
bench: (task, size, tids) => {
return bench('./main.bin run -t '+tids+' "(Main ' + size + ')" 2>/dev/null');
},
clean: () => {
exec("rm main.hvm");
exec("rm main.bin");
},
},
GHC: {
tids: [1],
tasks: {
"sort/bubble": [0, 64],
"sort/bitonic": [20, 24],
"sort/quick": [20, 24],
"sort/radix": [20, 24],
"lambda/arithmetic": [0, 120],
},
build: (task) => {
exec("cp ../../examples/"+task+"/main.hs main.hs");
exec("ghc -O2 main.hs -o main.bin");
},
bench: (task, size, tids) => {
return bench("./main.bin " + size);
},
clean: () => {
//exec("rm *.hs");
//exec("rm *.hi");
//exec("rm *.o");
//exec("rm *.bin");
},
},
};
// Enters the work directory
if (!fs.existsSync("work")) {
exec("mkdir work");
}
process.chdir("work");
// Runs benchmarks and collect results
var results = [];
for (var lang in langs) {
for (var tids of langs[lang].tids) {
//console.log(lang);
for (var task in langs[lang].tasks) {
langs[lang].build(task);
var min_size = langs[lang].tasks[task][0];
var max_size = SMALL ? min_size + 2 : langs[lang].tasks[task][1];
for (var size = min_size; size <= max_size; ++size) {
if (size === min_size) {
langs[lang].bench(task, size, tids); // dry-run to heat up
}
var time = langs[lang].bench(task, size, tids);
results.push({task, lang: lang+"-"+tids, size, time});
console.log(lang + "-" + tids + " | " + task + " | " + size + " | " + time.toFixed(3) + "s");
}
}
}
}
// Writes results to JSON
fs.writeFileSync("./../results.json", JSON.stringify(results, null, 2));
// Executes a command
function exec(str) {
try {
return exec_sync(str).toString();
} catch (e) {
console.log("OUT:", e.stdout.toString());
console.log("ERR:", e.stderr.toString());
return Infinity;
}
}
// Benchmarks a command
function bench(cmd) {
var ini = Date.now();
var res = exec(cmd, {skipThrow: 1}).toString().replace(/\n/g,"");
if (res == Infinity) { return Infinity }
var end = Date.now();
return (end - ini) / 1000;
}