-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrenderer.js
More file actions
65 lines (58 loc) · 1.63 KB
/
renderer.js
File metadata and controls
65 lines (58 loc) · 1.63 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
import { JsonTest } from "./JsonTest.js";
import { BinaryTest } from "./BinaryTest.js";
import { ThroughputTest } from "./ThroughputTest.js";
import { UiHelpers } from "./ui.js";
/** @type {MessagePort} */
let messagePort;
/** @type { Map<string, () => void> } */
const handlers = new Map();
let nextId = 0;
window.onmessage = (event) => {
const [port] = event.ports;
messagePort = port;
window.onmessage = null;
messagePort.onmessage = ({ data: { id, payload } }) => {
handlers.get(id)?.(payload); // resolve id
};
};
document.getElementById("StartTests").addEventListener("click", startTests);
async function sendViaMessagePort(payload) {
return new Promise((r) => {
const id = ++nextId;
handlers.set(id, r);
messagePort.postMessage({ id, payload });
});
}
async function sendViaIpcRenderer(payload) {
const id = ++nextId;
const response = await window.api.invoke("to-main", {
id,
payload,
});
return response.payload;
}
/** @param animate { boolean } */
async function startTests() {
UiHelpers.clearUI();
UiHelpers.setLoading(true);
// start binary test
const resultsBinary = await new BinaryTest(
sendViaMessagePort,
sendViaIpcRenderer
).run();
UiHelpers.outputTable(resultsBinary, "binary");
// start json test
const resultsJson = await new JsonTest(
sendViaMessagePort,
sendViaIpcRenderer
).run();
UiHelpers.outputTable(resultsJson, "json");
// start throughput test
const resultsThroughput = await new ThroughputTest(
handlers,
messagePort
).run();
UiHelpers.outputTable(resultsThroughput, "throughput");
UiHelpers.setLoading(false);
handlers.clear();
}