Skip to content

Instantly share code, notes, and snippets.

@LukeberryPi
Created November 20, 2023 16:19
Show Gist options
  • Save LukeberryPi/aef771b271c3e2d2c05502f49b1271fb to your computer and use it in GitHub Desktop.
Save LukeberryPi/aef771b271c3e2d2c05502f49b1271fb to your computer and use it in GitHub Desktop.
benchmark function for comparing performances in javascript
function benchmark(testName, callback) {
const startTime = performance.now();
callback();
const endTime = performance.now();
console.log(testName, `time: ${endTime - startTime}`);
}
// usage
function addNums(a, b) {
return a + b;
}
benchmark("addNums", () => addNums(10, 20));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment