Skip to content

Instantly share code, notes, and snippets.

@nathankellenicki
Created May 15, 2020 18:13
Show Gist options
  • Select an option

  • Save nathankellenicki/84be4c5499e9c005fba65b689c28f0d3 to your computer and use it in GitHub Desktop.

Select an option

Save nathankellenicki/84be4c5499e9c005fba65b689c28f0d3 to your computer and use it in GitHub Desktop.
// 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