-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonTest.js
More file actions
95 lines (94 loc) · 2.81 KB
/
JsonTest.js
File metadata and controls
95 lines (94 loc) · 2.81 KB
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
import { payload } from "./payload.js";
export class JsonTest {
/**
* @param sendViaMessagePort { () => Promise<void> }
* @param sendViaIpcRenderer { () => Promise<void> }
*/
constructor(sendViaMessagePort, sendViaIpcRenderer) {
this.sendViaMessagePort = sendViaMessagePort;
this.sendViaIpcRenderer = sendViaIpcRenderer;
}
createPayloads() {
this.PAYLOAD_1_KB = payload[1];
this.PAYLOAD_26_KB = payload[2];
this.PAYLOAD_500_KB = payload[3];
}
async run() {
this.createPayloads();
const suite = new Benchmark.Suite();
return new Promise((resolve) => {
suite
.add("MessagePort#Json#26KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaMessagePort(this.PAYLOAD_26_KB);
deferred.resolve();
},
})
.add("IpcRenderer#Json#26KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaIpcRenderer(this.PAYLOAD_26_KB);
deferred.resolve();
},
})
.add("MessagePort#Json#500KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaMessagePort(this.PAYLOAD_500_KB);
deferred.resolve();
},
})
.add("IpcRenderer#Json#500KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaIpcRenderer(this.PAYLOAD_500_KB);
deferred.resolve();
},
})
.add("MessagePort#Json#1KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaMessagePort(this.PAYLOAD_1_KB);
deferred.resolve();
},
})
.add("IpcRenderer#Json#1KB", {
defer: true,
fn: async (deferred) => {
await this.sendViaIpcRenderer(this.PAYLOAD_1_KB);
deferred.resolve();
},
})
// add listeners
.on("cycle", function (event) {
console.log(event.target.toString());
})
.on("complete", function () {
console.log(`ran on ${Benchmark.platform.description}`);
const results = this.sort(function (a, b) {
return b.hz - a.hz;
}).reduce(function (prev, cur) {
return (
(prev[cur.name] = Object.assign(
{
"ops/s": Number(cur.hz).toFixed(2),
samples: cur.stats.sample.length,
"margin of error": "\u00B1".concat(
Number(cur.stats.rme).toFixed(2),
"%"
),
},
cur.note !== undefined && {
note: cur.note,
}
)),
prev
);
}, {});
resolve(results);
})
.run();
});
}
}