Skip to content

Instantly share code, notes, and snippets.

@nkbt
Created February 2, 2018 02:18
Show Gist options
  • Save nkbt/3091d11e77513dc1469ff1381f16797f to your computer and use it in GitHub Desktop.
Save nkbt/3091d11e77513dc1469ff1381f16797f to your computer and use it in GitHub Desktop.

Revisions

  1. nkbt created this gist Feb 2, 2018.
    17 changes: 17 additions & 0 deletions perf.js
    Original 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);