Created
March 30, 2019 07:53
-
-
Save Alex1990/7d8930f2f7d80a21d21cedfb882539e1 to your computer and use it in GitHub Desktop.
Perf class
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
class Perf { | |
constructor () { | |
this.init() | |
this.phases = [] | |
} | |
init () { | |
const now = Date.now() | |
this.start = now | |
this.lastTime = now | |
} | |
getPhaseTime () { | |
const now = Date.now() | |
const phaseTime = now - this.lastTime | |
this.lastTime = now | |
return phaseTime | |
} | |
markPhase (label) { | |
this.phases.push({ label, time: this.getPhaseTime() }) | |
} | |
getAllPhases () { | |
let result = '' | |
this.phases.forEach(({ label, time }) => { | |
result += `${label}: ${time}ms\n` | |
}) | |
return result | |
} | |
getFullTime () { | |
return Date.now() - this.start | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment