-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbf2Worker.js
More file actions
25 lines (22 loc) · 756 Bytes
/
Copy pathbf2Worker.js
File metadata and controls
25 lines (22 loc) · 756 Bytes
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
importScripts('./BF2.js');
onmessage = async function(e) {
const { code, showTape } = e.data;
try {
const startTime = performance.now(); // Start time inside the worker
const interpreter = new BF2Interpreter(); // Create a new interpreter instance
const output = await interpreter.run(code, showTape);
let tapeOutput = '';
if (showTape) {
tapeOutput = output.tape.join('\n');
}
const endTime = performance.now(); // End time inside the worker
postMessage({
result: output.result,
operationCount: output.operationCount,
tape: tapeOutput,
executionTime: endTime - startTime, // Calculate time inside the worker
});
} catch (error) {
postMessage({ error: error.message });
}
};