-
-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathbenchmark-tests.js
44 lines (39 loc) · 1.2 KB
/
benchmark-tests.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
const { startWasiTask } = require("../lib");
const { performance } = require("perf_hooks");
global.benchmarkRunner = function (name, body) {
console.log(`Running '${name}' ...`);
const startTime = performance.now();
body(5000);
const endTime = performance.now();
console.log("done " + (endTime - startTime) + " ms");
};
class JSBenchmark {
constructor(title) {
this.title = title;
}
testSuite(name, body) {
benchmarkRunner(`${this.title}/${name}`, (iteration) => {
for (let idx = 0; idx < iteration; idx++) {
body();
}
});
}
}
const serialization = new JSBenchmark("Serialization");
serialization.testSuite("Write JavaScript number directly", () => {
const jsNumber = 42;
const object = global;
for (let idx = 0; idx < 100; idx++) {
object["numberValue" + idx] = jsNumber;
}
});
serialization.testSuite("Write JavaScript string directly", () => {
const jsString = "Hello, world";
const object = global;
for (let idx = 0; idx < 100; idx++) {
object["stringValue" + idx] = jsString;
}
});
startWasiTask("./dist/BenchmarkTests.wasm").catch((err) => {
console.log(err);
});