pinafore/routes/_utils/marks.js
Nolan Lawson 5c53199434 lint fix
2018-02-21 17:57:49 -08:00

27 lines
591 B
JavaScript

import { thunk } from './thunk'
// Lazily invoke because URLSearchParams isn't supported in Edge 16,
// so we need the polyfill.
const enabled = thunk(() => process.browser &&
performance.mark &&
(
process.env.NODE_ENV !== 'production' ||
new URLSearchParams(location.search).get('marks') === 'true'
)
)
const perf = process.browser && performance
export function mark (name) {
if (enabled()) {
perf.mark(`start ${name}`)
}
}
export function stop (name) {
if (enabled()) {
perf.mark(`end ${name}`)
perf.measure(name, `start ${name}`, `end ${name}`)
}
}