Advertisement
ajxtaylor-google

TypeScript simple benchmark timer

Jun 14th, 2017
630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Timer {
  2.   readonly start = performance.now();
  3.  
  4.   constructor(private readonly name: string) {}
  5.  
  6.   stop() {
  7.     const time = performance.now() - this.start;
  8.     console.log('Timer:', this.name, 'finished in', Math.round(time), 'ms');
  9.   }
  10. }
  11.  
  12. const t = new Timer('Some label');
  13. // Code to benchmark
  14. t.stop(); // Prints the time elapsed to the JS console.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement