Created
May 10, 2017 16:01
-
-
Save sterlingwes/acb1fefb295c3847730cf28723437868 to your computer and use it in GitHub Desktop.
Performance timing with window.performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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