Skip to content

Instantly share code, notes, and snippets.

@fabriciofmsilva
Last active July 26, 2019 19:28
Show Gist options
  • Save fabriciofmsilva/a42d5201b9a5a70deea1e792c045a3cd to your computer and use it in GitHub Desktop.
Save fabriciofmsilva/a42d5201b9a5a70deea1e792c045a3cd to your computer and use it in GitHub Desktop.
Performance Testing JavaScript

Performance Testing JavaScript

Testing performance is surprisingly straightforward.

  1. Start a timer
  2. Run your tasks
  3. Stop the timer and note how much time has elapsed
  • The performance.now() method
  • The console.time() and console.timeEnd() methods
var start = performance.now();
// Do some JS stuff...
var end = performance.now();

console.log('This took ' + (end - start) + 'ms to complete');
console.time('My awesome performance test!');
// Do some JS stuff...
console.timeEnd('My awesome performance test!');
// This will log "My awesome performance test!: 1234.567ms" (with the actual time, of course)

Run 10,000 times, get average

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment