Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

perf: update ms to use performance.now() for more accurate time measurements #298

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
});