2018-02-22 01:52:33 +00:00
|
|
|
import { thunk } from './thunk'
|
2018-01-17 08:59:15 +00:00
|
|
|
|
2018-02-22 01:52:33 +00:00
|
|
|
// Lazily invoke because URLSearchParams isn't supported in Edge 16,
|
|
|
|
// so we need the polyfill.
|
|
|
|
const enabled = thunk(() => process.browser &&
|
2018-02-10 19:36:31 +00:00
|
|
|
performance.mark &&
|
2018-02-22 01:52:33 +00:00
|
|
|
(
|
|
|
|
process.env.NODE_ENV !== 'production' ||
|
|
|
|
new URLSearchParams(location.search).get('marks') === 'true'
|
|
|
|
)
|
|
|
|
)
|
2018-01-17 08:59:15 +00:00
|
|
|
|
2018-02-10 19:36:31 +00:00
|
|
|
const perf = process.browser && performance
|
|
|
|
|
2018-02-22 01:57:49 +00:00
|
|
|
export function mark (name) {
|
2018-02-22 01:52:33 +00:00
|
|
|
if (enabled()) {
|
|
|
|
perf.mark(`start ${name}`)
|
|
|
|
}
|
2018-02-10 19:36:31 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 01:57:49 +00:00
|
|
|
export function stop (name) {
|
2018-02-22 01:52:33 +00:00
|
|
|
if (enabled()) {
|
|
|
|
perf.mark(`end ${name}`)
|
|
|
|
perf.measure(name, `start ${name}`, `end ${name}`)
|
|
|
|
}
|
2018-02-22 01:57:49 +00:00
|
|
|
}
|