Skip to content

Instantly share code, notes, and snippets.

@jasonsturges
Created August 26, 2020 06:31
Show Gist options
  • Save jasonsturges/6b15e39c8e0049a3f96bd9b4a3a9180e to your computer and use it in GitHub Desktop.
Save jasonsturges/6b15e39c8e0049a3f96bd9b4a3a9180e to your computer and use it in GitHub Desktop.
Benchmarking JavaScript - Tuning execution time
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();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment