Skip to content

Instantly share code, notes, and snippets.

@jasonsturges
Created August 26, 2020 06:51
Show Gist options
  • Save jasonsturges/a3f4e2a6696647084cbc49abdff918f8 to your computer and use it in GitHub Desktop.
Save jasonsturges/a3f4e2a6696647084cbc49abdff918f8 to your computer and use it in GitHub Desktop.
Benchmarking JavaScript - Asynchronous execution
const runTest = (iterations = 100000000) => {
let startTime = new Date().getTime();
for (let i = 0; i < iterations; i++)
Math.log10(0)
let endTime = new Date().getTime();
let totalTime = endTime - startTime;
let fnTime = (totalTime / iterations).toFixed(10);
let operations = Math.floor(1000 / totalTime * iterations);
console.log(`total: ${totalTime}, time: ${fnTime}, op/sec: ${operations}`);
}
while (true) {
runTest();
await sleep(50);
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment