Last active
March 29, 2019 18:25
-
-
Save StrykerKent/722a1871d734ae431e73090dc7ea270e to your computer and use it in GitHub Desktop.
Reviewing / Measuring / Timing O(n) performance using JavaScript, NFL Players, functions, for loops, and performance.now(). For use in browser, not node.js.
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
const players = [ | |
'Tom Brady', | |
'Aaron Rodgers', | |
'Drew Brees', | |
'Ben Roethlisberger', | |
'Philip Rivers', | |
'Aqib Talib', | |
'Alex Smith', | |
'Larry Fitzgerald' | |
]; | |
function getPlayer(player, array) { | |
let t0 = performance.now(); | |
for (let i = 0; i < array.length; i++ ) { | |
if (array[i] === player) { | |
console.log('Found player', player); | |
} | |
} | |
let t1 = performance.now(); | |
console.log(`t0= ${t0} t1 = ${t1}`); | |
console.log(`Finding player ${player} took ${t1-t0} milliseconds.`); | |
} | |
getPlayer('Philip Rivers', players); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment