diff --git a/packages/app/src/classes/PerformanceLog/index.js b/packages/app/src/classes/PerformanceLog/index.js new file mode 100644 index 00000000..528f6c38 --- /dev/null +++ b/packages/app/src/classes/PerformanceLog/index.js @@ -0,0 +1,53 @@ +export default class PerformanceLog { + constructor( + id, + params = { + disabled: false + } + ) { + this.id = id + this.params = params + + this.table = {} + + return this + } + + start(event) { + if (this.params.disabled) { + return false + } + + if (!this.table[event]) { + this.table[event] = {} + } + + return this.table[event]["start"] = performance.now() + } + + end(event) { + if (this.params.disabled) { + return false + } + + if (!this.table[event]) { + return + } + + return this.table[event]["end"] = performance.now() + } + + finally() { + if (this.params.disabled) { + return false + } + + console.group(this.id) + + Object.entries(this.table).forEach(([entry, value]) => { + console.log(entry, `${(value.end - value.start).toFixed(0)}ms`) + }) + + console.groupEnd() + } +} \ No newline at end of file