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: update time formatting #29629

Closed
wants to merge 3 commits into from
Closed

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Sep 20, 2019

This improves the readability of the console.timeEnd() output
while keeping a higher output's precision in multiple cases.

Instead of e.g. '1.005min' it will print '1min and 300ms'.

It also rounds full numbers (e.g., 1.1 instead of 1.100). It would also be possible to always print seconds and milliseconds as one value, since that's easy to read. This just seemed even clearer and more straight forward.

This relies on a semver-major commit (#29251). As long as it lands together with the other commit, it should be fine to land this as a patch instead of being semver-major itself.

I requested the reviewers from the former commit to also review this PR.
CC @Xstoudi

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

@nodejs-github-bot nodejs-github-bot added the console Issues and PRs related to the console subsystem. label Sep 20, 2019
@addaleax
Copy link
Member

addaleax commented Sep 20, 2019

Instead of e.g. '1.005min' it will print '1min and 300ms'.

I think this can be a reasonable choice for end-user-facing output, but generally isn’t for developer-facing output (like the console time APIs) where easy comparisons are more important than having an easy time converting the value to how it would be described in informal conversation.

If you do want to display these values separately, I’d suggest using a more standard format like hh:mm:ss.mmm.

This improves the readability of the `console.timeEnd()` output
while keeping a higher output's precision in multiple cases.

Instead of e.g. '1.005min' it will print '1m and 300ms'.
@BridgeAR
Copy link
Member Author

@addaleax I mainly switched to your suggestion. PTAL

@Trott Trott added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 24, 2019
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@Trott
Copy link
Member

Trott commented Sep 25, 2019

@nodejs/console

assert.strictEqual(formatTime(60300.3), '1:00.300 (m:ss.mmm)');
assert.strictEqual(formatTime(4000457.4), '1:06:40.457 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3601310.4), '1:00:01.310 (h:mm:ss.mmm)');
assert.strictEqual(formatTime(3213601017.6), '892:40:01.018 (h:mm:ss.mmm)');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we're outputting the literal string "hh:mm:as.mmm"? i think this format is standard enough that we don't have to do that.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess most people will know about it but I added it to leave no doubt. I would like to support people who are not yet that experienced as well.

assert.strictEqual(formatTime(100.0096), '100.01ms');
assert.strictEqual(formatTime(100.0115), '100.011ms');
assert.strictEqual(formatTime(1500.04), '1.500s');
assert.strictEqual(formatTime(1000.056), '1.000s');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep these consistent with the higher numbers, to be honest...

e.g.

Suggested change
assert.strictEqual(formatTime(1000.056), '1.000s');
assert.strictEqual(formatTime(1000.056), '1.000 (ss.mmm)');

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seconds and milliseconds are the most common ones. People will rarely reach the higher values and it seems more straight forward to me to keep s and ms as common cases.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I understand the reasoning, I just disagree :) I'd rather opt for consistency.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to remove the author ready label out of caution while this gets sorted, but feel free to re-add it if that's overly-cautious of me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasnell is your comment blocking? I would rather close this PR than changing the common cases (even though I believe that this PR does improve the overall output).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not blocking but I definitely don't consider the inconsistency to be ideal.

@Trott Trott removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Sep 27, 2019
BridgeAR added a commit that referenced this pull request Oct 1, 2019
This improves the readability of the `console.timeEnd()` output
while keeping a higher output's precision in multiple cases.

Instead of e.g. '1.005min' it will print '1:00.300 (m:ss.mmm)'.

PR-URL: #29629
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
@BridgeAR
Copy link
Member Author

BridgeAR commented Oct 1, 2019

Landed in 204248a

@BridgeAR BridgeAR closed this Oct 1, 2019
@BridgeAR BridgeAR deleted the format-time branch January 20, 2020 12:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
console Issues and PRs related to the console subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants