Skip to content

Instantly share code, notes, and snippets.

Created February 2, 2018 02:18
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save nkbt/3091d11e77513dc1469ff1381f16797f to your computer and use it in GitHub Desktop.
Namespaced perf measurer
const perfCache = {start: {}, end: {}};
const perf = key => {
if (key in perfCache.end) {
return perfCache.end[key];
if (key in perfCache.start) {
const [s, ns] = process.hrtime(perfCache.start[key]);
Object.assign(perfCache.end, {[key]: (s + ns / 1e9)});
return perfCache.end[key];
Object.assign(perfCache.start, {[key]: process.hrtime()});
return perfCache.start[key];
setTimeout(() => console.log(perf('whatever')), 500);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment