Skip to content

Commit

Permalink
perf: update ms to use performance.now() for more accurate time measu…
Browse files Browse the repository at this point in the history
…rements
  • Loading branch information
johnnyhuirilef committed Dec 13, 2023
1 parent ded082a commit ac9e32d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions ms.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

const { performance } = require('perf_hooks');
const format = require('./format');
const ms = require('ms');

Expand All @@ -8,11 +9,11 @@ const ms = require('ms');
* Returns an `info` with a `ms` property. The `ms` property holds the Value
* of the time difference between two calls in milliseconds.
*/
module.exports = format(info => {
const curr = +new Date();
module.exports = format((info) => {
const curr = performance.now();
this.diff = curr - (this.prevTime || curr);
this.prevTime = curr;
info.ms = `+${ms(this.diff)}`;
info.ms = `+${ms(Math.round(this.diff))}`;

return info;
});

0 comments on commit ac9e32d

Please sign in to comment.