Created
May 15, 2020 18:13
-
-
Save nathankellenicki/84be4c5499e9c005fba65b689c28f0d3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // Simple metrics gathering | |
| export default class SimpleMetrics { | |
| constructor () { | |
| this.mainStartTime = +(new Date()); | |
| this.startTimings = {}; | |
| this.reportedTimings = []; | |
| } | |
| startTiming () { | |
| this.mainStartTime = +(new Date()); | |
| }; | |
| startMetric (name) { | |
| console.log(`LOG: Starting ${name}`); | |
| this.startTimings[name] = +(new Date()) - this.mainStartTime; | |
| }; | |
| endMetric (name) { | |
| console.log(`LOG: Ending ${name}`); | |
| const endTime = +(new Date()); | |
| this.reportedTimings.push({ | |
| name, | |
| endTime: endTime - this.mainStartTime, | |
| startTime: this.startTimings[name], | |
| duration: (endTime - this.mainStartTime) - this.startTimings[name], | |
| }); | |
| }; | |
| printMetrics () { | |
| console.log(JSON.stringify(this.reportedTimings)); | |
| this.reportedTimings = []; | |
| this.startTimings = {}; | |
| }; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment