pinafore/routes/_utils/marks.js

26 lines
519 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
function doMark(name) {
perf.mark(`start ${name}`)
}
function doStop(name) {
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
}