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

console: display timeEnd with suitable time unit #29251

Closed
wants to merge 9 commits into from

console: extract formatTime and export it for test

Extract the format time part to be able to test it.
  • Loading branch information
Xstoudi committed Aug 21, 2019
commit c4eb2d66339310215c5659104500705276b43224
@@ -519,6 +519,17 @@ function timeLogImpl(self, name, label, data) {
const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6;

const formatted = formatTime(ms);

if (data === undefined) {
self.log('%s: %s', label, formatted);
} else {
self.log('%s: %s', label, formatted, ...data);
}
return true;
}

function formatTime(ms) {
let value = ms;
let unit = 'ms';

@@ -533,12 +544,7 @@ function timeLogImpl(self, name, label, data) {
unit = 's';
}

if (data === undefined) {
self.log('%s: %s%s', label, value.toFixed(3), unit);
} else {
self.log('%s: %s%s', label, value.toFixed(3), unit, ...data);
}
return true;
return value.toFixed(3) * 1 + unit;
}

const keyKey = 'Key';
@@ -562,5 +568,6 @@ Console.prototype.groupCollapsed = Console.prototype.group;
module.exports = {
Console,
kBindStreamsLazy,
kBindProperties
kBindProperties,
formatTime // exported for tests
};
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.