Skip to content

Instantly share code, notes, and snippets.

@Alex1990
Created March 30, 2019 07:53
Show Gist options
  • Save Alex1990/7d8930f2f7d80a21d21cedfb882539e1 to your computer and use it in GitHub Desktop.
Save Alex1990/7d8930f2f7d80a21d21cedfb882539e1 to your computer and use it in GitHub Desktop.
Perf class
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