benchmark.js 441 B

1234567891011121314151617181920212223242526
  1. class Benchmark {
  2. start() {
  3. this.tstart = process.hrtime();
  4. return this;
  5. }
  6. mark() {
  7. this.diff = process.hrtime(this.tstart);
  8. this.tstart = process.hrtime();
  9. return this;
  10. }
  11. toString() {
  12. var msdiff = ( this.diff[0] * 1000000 + this.diff[1] / 1000 ) /1000;
  13. if(msdiff > 1000)
  14. return (msdiff / 1000).toFixed(2) + "s";
  15. else {
  16. return msdiff.toFixed(2) +"ms";
  17. }
  18. return "NaN";
  19. }
  20. }
  21. module.exports = Benchmark;