Skip to content

Instantly share code, notes, and snippets.

@wbamberg
Created May 13, 2021 18:14
Show Gist options
  • Save wbamberg/cbc44eb037f1fd58f3390a5566f38014 to your computer and use it in GitHub Desktop.
Save wbamberg/cbc44eb037f1fd58f3390a5566f38014 to your computer and use it in GitHub Desktop.
let last = 0; // last millisecond recorded
let lineno = 0; // current output line number
const iterations = 15;
let count = 0;
function timeout() {
logline(new Date().getMilliseconds());
count = count + 1;
if (count < iterations) {
setTimeout(timeout, 0);
}
}
function run() {
setTimeout(timeout, 0);
}
function logline(msec) { // msec can't wrap: run duration > 1 second
const newLine = document.createElement("pre");
newLine.textContent = `${pad(lineno++, 2)} ${pad(last, 3)} ${pad(msec, 3)}`;
document.getElementById("log").appendChild(newLine);
last = msec;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment