Skip to content

Instantly share code, notes, and snippets.

@larshp
Created September 2, 2016 10:19
Show Gist options
  • Save larshp/046285a8e1e13caee0b8ebaaadcfb012 to your computer and use it in GitHub Desktop.
Save larshp/046285a8e1e13caee0b8ebaaadcfb012 to your computer and use it in GitHub Desktop.
class Timer {
private times;
private count;
private startTime: number;
public constructor() {
this.times = {};
this.count = {};
}
public start(): void {
this.startTime = new Date().getTime();
}
public stop(name: string): void {
let end = new Date().getTime();
let time = end - this.startTime;
if (this.times[name]) {
this.times[name] = this.times[name] + time;
this.count[name] = this.count[name] + 1;
} else {
this.times[name] = time;
this.count[name] = 1;
}
}
public output(filename: string) {
for (let name in this.times) {
if (this.times[name] > 100) {
console.log(name + "\t" + this.times[name] + "ms\t" + this.count[name] + "\t" + filename);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment