Skip to content

Instantly share code, notes, and snippets.

@cicconewk
Last active February 1, 2022 19:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cicconewk/c281d852c30496b71ac3b980c21fa8c2 to your computer and use it in GitHub Desktop.
Save cicconewk/c281d852c30496b71ac3b980c21fa8c2 to your computer and use it in GitHub Desktop.
It's the first attempt to test the performance of a function that given an array will return a certain value.
const nemo = ["nemo"];
function findNemo(array) {
let t0 = performance.now();
for (let i = 0; i < array.lenght; i++) {
if (array[i] === "nemo") {
console.log("Found NEMO!");
}
}
let t1 = performance.now();
console.log(`Call to find Nemo took ${t1 - t0} milliseconds`);
}
findNemo(nemo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment