Skip to content

Commit

Permalink
icecup time counter now ticks upwards during execution
Browse files Browse the repository at this point in the history
  • Loading branch information
HighDiceRoller committed Oct 9, 2024
1 parent 4a48a26 commit 2a6311b
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions apps/icecup.html
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,6 @@ <h2>Useful links</h2>
}

var usedRandom = false;
var computationTime = 0.0;
var prevCode = '';

async function runCode(code, probabilityType, transpose) {
Expand All @@ -347,16 +346,15 @@ <h2>Useful links</h2>
await resetIcepool();
self.postMessage({ cmd: 'clearError' });
pyodide.runPython(`_manager.reset()`);
let code_in_main = 'def main():\n' + code.replace(/^/gm, ' ') + '\nmain()';
self.postMessage({ cmd: 'setStartTime' });
try {
let code_in_main = 'def main():\n' + code.replace(/^/gm, ' ') + '\nmain()';
let computationStart = performance.now();
pyodide.runPython(code_in_main);
usedRandom = pyodide.runPython(`_manager.used_random()`);
computationTime = (performance.now() - computationStart) / 1000.0;
self.postMessage({ cmd: 'updateComputationTime', computationTime });
} catch (err) {
self.postMessage({ cmd: 'appendError', text: err + '\n'});
}
self.postMessage({ cmd: 'setEndTime' });
prevCode = code;
}

Expand All @@ -383,6 +381,9 @@ <h2>Useful links</h2>
const worker_blob = new Blob([document.getElementById('icecupWorker').textContent],
{type: "text/javascript"});

var startTime = 0.0;
var endTime = 0.0;

function createPyodideWorker() {
let worker = new Worker(window.URL.createObjectURL(worker_blob));
worker.onmessage = (msg) => {
Expand All @@ -396,8 +397,10 @@ <h2>Useful links</h2>
appendError(msg.data.text);
} else if (msg.data.cmd === "updateChart") {
updateChart(msg.data.labels, msg.data.datasets);
} else if (msg.data.cmd === "updateComputationTime") {
updateComputationTime(msg.data.computationTime);
} else if (msg.data.cmd === "setStartTime") {
startTime = performance.now();
} else if (msg.data.cmd === "setEndTime") {
endTime = performance.now();
} else if (msg.data.cmd === "setLoadingText") {
setLoadingText(msg.data.text);
} else if (msg.data.cmd === "setIcepoolVersion") {
Expand Down Expand Up @@ -591,10 +594,6 @@ <h2>Useful links</h2>
chart.update();
}

function updateComputationTime(computationTime) {
document.getElementById("computation_time").textContent = 'Computation time: ' + computationTime.toFixed(3) + ' s';
}

function updateLogScale() {
updateSearchQuery();
if (document.getElementById('ls').checked) {
Expand Down Expand Up @@ -636,6 +635,17 @@ <h2>Useful links</h2>

// Initial run.
updateLogScale();

setInterval(() => {
let computationTime = 0.0;
if (endTime >= startTime) {
computationTime = endTime - startTime;
} else {
computationTime = performance.now() - startTime;
}
document.getElementById("computation_time").textContent = 'Computation time: ' + (computationTime * 0.001).toFixed(3) + ' s';
}, 100)

runCode();

</script>
Expand Down

0 comments on commit 2a6311b

Please sign in to comment.