Created
November 20, 2023 16:19
-
-
Save LukeberryPi/aef771b271c3e2d2c05502f49b1271fb to your computer and use it in GitHub Desktop.
benchmark function for comparing performances in javascript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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