JSFiddle - React, Tailwind, and code Playground
by Don Denton
HTML
Closer to 1.0 calls/second is best<br>
<p id="o"></p>
<p id="p"></p>
JavaScript
// To simulate a non-trivial calculation
function sleep(milliseconds) {
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
var ct = 0, o=document.querySelector('#o');
function interval() {
var time = (new Date - start) / 1000;
var avg = ++ct / time;
o.innerHTML = ct+" interval calls in "+time.toFixed(3)+"s is "+avg.toFixed(6)+" calls/second";
sleep(2);
}
var ct2 = 0, p=document.querySelector('#p');
function count() {
var time = (new Date - start) / 1000;
var avg = ++ct2 / time;
p.innerHTML = ct2+" timeout calls in "+time.toFixed(3)+"s is "+avg.toFixed(6)+" calls/second";
sleep(2);
setTimeout(count, 1000);
}
var start = +new Date
setInterval(interval, 1000);
setTimeout(count, 1000);