Created
February 2, 2018 02:18
-
-
Save nkbt/3091d11e77513dc1469ff1381f16797f to your computer and use it in GitHub Desktop.
Revisions
-
nkbt created this gist
Feb 2, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,17 @@ 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);