You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

22 lines
655 B

module.exports = class TimeProfiler {
constructor (pTag, pHideIt) {
this.hideIt = !!pHideIt
this.tag = pTag || 'TimeProfile'
this.list = [{title: 'Init', date: new Date()}]
}
tick (pTitle) {
this.list.push({title: pTitle, date: new Date()})
}
done () {
if (this.hideIt) return
console.log('Profiling results for:' + this.tag)
console.log(' - ' + this.list[0].title + ': 0')
for (var i = 1; i < this.list.length; i++) {
console.log(' - ' + this.list[i].title + ': ' + (this.list[i].date - this.list[i - 1].date))
}
console.log(' - TOTAL', (new Date()) - this.list[0].date)
this.list = []
}
}