Skip to content

Instantly share code, notes, and snippets.

@lukechilds
Created April 11, 2017 06:09
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukechilds/f2cfe9257da2b387acc31c7616b1dec4 to your computer and use it in GitHub Desktop.
Save lukechilds/f2cfe9257da2b387acc31c7616b1dec4 to your computer and use it in GitHub Desktop.
JavaScript performance testing accurate to 5 microseconds in 59 bytes

Performance testing accurate to 5 microseconds in 57 bytes

Test JavaScript methods against each other accurate to 5 microseconds (five thousandths of a millisecond).

Usage

time = fn=>{let t=()=>performance.now(),s=t();fn();return t()-s}
time(() => document.querySelectorAll('span'))
// 0.18499999959021807
time(() => document.getElementsByTagName('span'))
// 0.04000000050291419
fn=>{let t=()=>performance.now(),s=t();fn();return t()-s}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment