Skip to content

Commit 1ba7486

Browse files
committed
Update worker to show elapsed time
1 parent 77f5c08 commit 1ba7486

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

electra_web/worker.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ onmessage = async (e) => {
2323
function loop() {
2424
Electra.init(input);
2525
Electra.set_source_code(code);
26+
const start = performance.now();
2627
Electra.generate();
2728
Electra.step();
2829

@@ -35,5 +36,17 @@ function loop() {
3536
postMessage({ type: "output", data: output });
3637
}
3738
}
38-
postMessage({ type: "final", data: "\n[Program finished]\n" });
39+
const end = performance.now();
40+
const delta_time = (end - start);
41+
const ms = Math.floor(delta_time % 1000);
42+
const seconds = Math.floor(delta_time / 1e3) % 60;
43+
const mins = Math.floor(delta_time / (1e3 * 60)) % 60;
44+
const hours = Math.floor(delta_time / (1e3 * 3600));
45+
let final_text = "";
46+
if(hours > 0) { final_text += `${hours}h `; }
47+
if(mins > 0) { final_text += `${mins}m `; }
48+
if(seconds > 0) { final_text += `${seconds}s `; }
49+
final_text += `${ms}ms`;
50+
51+
postMessage({ type: "final", data: `\n[Execution completed in ${final_text}]\n` });
3952
}

0 commit comments

Comments
 (0)