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 = [] } }