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]; }; perf('whatever'); setTimeout(() => console.log(perf('whatever')), 500);