pinafore/routes/_utils/marks.js

26 lines
521 B
JavaScript
Raw Normal View History

2018-01-17 09:59:15 +01:00
import noop from 'lodash/noop'
2018-01-31 17:40:37 +01:00
const enableMarks = process.browser &&
2018-02-10 20:36:31 +01:00
performance.mark &&
2018-01-31 17:40:37 +01:00
(process.env.NODE_ENV !== 'production' ||
new URLSearchParams(location.search).get('marks') === 'true')
2018-01-17 09:59:15 +01:00
2018-02-10 20:36:31 +01:00
const perf = process.browser && performance
2018-02-11 18:37:13 +01:00
function doMark (name) {
2018-02-10 20:36:31 +01:00
perf.mark(`start ${name}`)
}
2018-02-11 18:37:13 +01:00
function doStop (name) {
2018-02-10 20:36:31 +01:00
perf.mark(`end ${name}`)
perf.measure(name, `start ${name}`, `end ${name}`)
}
const mark = enableMarks ? doMark : noop
const stop = enableMarks ? doStop : noop
2018-01-17 09:59:15 +01:00
export {
mark,
stop
2018-02-09 07:29:29 +01:00
}