Skip to content

Instantly share code, notes, and snippets.

@codeNameAtlas
Created September 7, 2018 17:40
Show Gist options
  • Save codeNameAtlas/ca9b421daa9786b3835729979abd080a to your computer and use it in GitHub Desktop.
Save codeNameAtlas/ca9b421daa9786b3835729979abd080a to your computer and use it in GitHub Desktop.
User timing api exercise with chrome
// set iterations high to measure performance at scale on a simple function
let iterations = 1e7;
const a = 1;
const b = 2;
const add = (x, y) => x + y;
// start measuring performance
performance.mark('start');
// code to measure
while (iterations--) {
add(a, b);
}
// end measuring performance
performance.mark('end');
performance.measure('My Special Benchmark', 'start', 'end');
const [ measure ] = performance.getEntriesByName('My Special Benchmark');
// output the results to the console
console.log(measure);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment