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