Skip to content

Instantly share code, notes, and snippets.

@jokecamp
Created June 9, 2020 13:29
Show Gist options
  • Save jokecamp/254be97380838aa5f1787c8a96f1dbe6 to your computer and use it in GitHub Desktop.
Save jokecamp/254be97380838aa5f1787c8a96f1dbe6 to your computer and use it in GitHub Desktop.
class Timer {
readonly start = performance.now();
constructor(private readonly name: string) {}
stop() {
const time = performance.now() - this.start;
console.log('Timer:', this.name, 'finished in', Math.round(time), 'ms');
}
}
private t: Timer;
// When change detection begins
ngDoCheck() {
this.t = new Timer('Cardbock block render');
}
// When change detection has finished:
// child components created, all *ngIfs evaluated
ngAfterViewChecked() {
this.t.stop(); // Prints the time elapsed to the JS console.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment