Skip to content

Instantly share code, notes, and snippets.

@sterlingwes
Created May 10, 2017 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sterlingwes/acb1fefb295c3847730cf28723437868 to your computer and use it in GitHub Desktop.
Save sterlingwes/acb1fefb295c3847730cf28723437868 to your computer and use it in GitHub Desktop.
Performance timing with window.performance
const perf = window.performance
class PerformanceTimer {
constructor (name) {
this.name = name
this.markStart = `${name}-start`
this.markStop = `${name}-stop`
}
start () {
perf.mark(this.markStart)
return this
}
stop () {
perf.mark(this.markStop)
return this
}
measure () {
const { name, markStart, markStop } = this
perf.measure(name, markStart, markStop)
return perf.getEntriesByName(name, 'measure')
}
}
export default PerformanceTimer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment