Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
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
You can’t perform that action at this time.