JSFiddle - React, Tailwind, and code Playground
JavaScript
async function doit() {
function time(location) {
return new Promise((done) => {
const start = Date.now();
const frame = document.createElement('script');
frame.setAttribute('src', location);
const onFinish = () => {
const stop = Date.now();
const disp = document.createElement('div');
disp.innerText = location + ': ' + (stop - start) + 'ms\n';
document.body.appendChild(disp);
clearTimeout(timeout);
//requestAnimationFrame(() => {time(location); });
done();
};
const timeout = setTimeout(() => {
onFinish();
document.body.removeChild(frame);
}, 5000);
frame.addEventListener('load', onFinish);
frame.addEventListener('error', onFinish);
document.body.appendChild(frame);
});
}
for (i = 0; i < 255; i++) {
await time('https://192.168.0.' + i);
}
}
doit();