Pinafore-Web-Client-Frontend/routes/_utils/marks.js

27 lines
591 B
JavaScript
Raw Normal View History

2018-02-22 02:52:33 +01:00
import { thunk } from './thunk'
2018-01-17 09:59:15 +01:00
2018-02-22 02:52:33 +01:00
// Lazily invoke because URLSearchParams isn't supported in Edge 16,
// so we need the polyfill.
const enabled = thunk(() => process.browser &&
2018-02-10 20:36:31 +01:00
performance.mark &&
2018-02-22 02:52:33 +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-22 02:57:49 +01:00
export function mark (name) {
2018-02-22 02:52:33 +01:00
if (enabled()) {
perf.mark(`start ${name}`)
}
2018-02-10 20:36:31 +01:00
}
2018-02-22 02:57:49 +01:00
export function stop (name) {
2018-02-22 02:52:33 +01:00
if (enabled()) {
perf.mark(`end ${name}`)
perf.measure(name, `start ${name}`, `end ${name}`)
}
2018-02-22 02:57:49 +01:00
}