-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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: sub-millisecond accuracy for console.time #3166
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,18 +72,18 @@ object. This is useful for inspecting large complicated objects. Defaults to | |
- `colors` - if `true`, then the output will be styled with ANSI color codes. | ||
Defaults to `false`. Colors are customizable, see below. | ||
|
||
### console.time(label) | ||
### console.time(timerName) | ||
|
||
Used to calculate the duration of a specific operation. To start a timer, call | ||
the `console.time()` method, giving it a name as only parameter. To stop the | ||
timer, and to get the elapsed time in milliseconds, just call the | ||
[`console.timeEnd()`](#console_console_timeend_label) method, again passing the | ||
timer's name as the parameter. | ||
Starts a timer that can be used to compute the duration of an operation. Timers | ||
are identified by a unique name. Use the same name when you call | ||
[`console.timeEnd()`](#console_console_timeend_timername) to stop the timer and | ||
output the elapsed time in milliseconds. Timer durations are accurate to the | ||
sub-millisecond. | ||
|
||
### console.timeEnd(label) | ||
### console.timeEnd(timerName) | ||
|
||
Stops a timer that was previously started by calling | ||
[`console.time()`](#console_console_time_label) and print the result to the | ||
[`console.time()`](#console_console_time_timername) and prints the result to the | ||
console. | ||
|
||
Example: | ||
|
@@ -93,7 +93,7 @@ Example: | |
; | ||
} | ||
console.timeEnd('100-elements'); | ||
// prints 100-elements: 262ms | ||
// prints 100-elements: 225.438ms | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why this change is necessary? Edit: Ah, I see it now. That is kind of the point of this PR There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bikeshedding: this belongs to the first commit «console: sub-millisecond accuracy for console.time», not to «doc: reword description of console.time». There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I moved this change to the first commit |
||
|
||
### console.trace(message[, ...]) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,8 +68,8 @@ assert.notEqual(-1, strings.shift().indexOf('foo: [Object]')); | |
assert.equal(-1, strings.shift().indexOf('baz')); | ||
assert.equal('Trace: This is a {"formatted":"trace"} 10 foo', | ||
strings.shift().split('\n').shift()); | ||
assert.ok(/^label: \d+ms$/.test(strings.shift().trim())); | ||
assert.ok(/^__proto__: \d+ms$/.test(strings.shift().trim())); | ||
assert.ok(/^constructor: \d+ms$/.test(strings.shift().trim())); | ||
assert.ok(/^hasOwnProperty: \d+ms$/.test(strings.shift().trim())); | ||
assert.ok(/^label: \d+\.\d{3}ms$/.test(strings.shift().trim())); | ||
assert.ok(/^__proto__: \d+\.\d{3}ms$/.test(strings.shift().trim())); | ||
assert.ok(/^constructor: \d+\.\d{3}ms$/.test(strings.shift().trim())); | ||
assert.ok(/^hasOwnProperty: \d+\.\d{3}ms$/.test(strings.shift().trim())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we consider the output of the console functions to be part of the API, the I think one could view this as semver-major. The change to thses tests demonstrates how downstream apps output parsing will break. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I don't know what is the policy about console output. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm going to say semver-minor for changes to console output but it's never as clear cut as it appears. For this, I personally feel it's small enough of a change that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The probability of this breaking anything is near zero. Still, there seems to be no reason for pulling this into 4.x branch. |
||
assert.equal(strings.length, 0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nittiest of all possible nits: The last sentence describes the timer precision, not the accuracy.
Slightly less nitty nit:
sub-millisecond
is true, but we know that it will be three decimal places, so you could just say it's to the microsecond.Of course, I can't come up with wording for either of these nits that's better than what's already there, so ¯_(ツ)_/¯
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are right, I will replace "accurate" with "precise" when I land it if nobody objects.
I wanted to do that but I am not sure it's true all the time and on all platforms. Perhaps if the CPU is overloaded we can lose precision ? I really don't know.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possibility is just to remove that last sentence entirely. I don't think MDN indicates how many decimal places their timer is good for, for example. People can use it and they get as many decimal places as they get.
MDN stuff for reference:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this sentence I took inspiration from https://developer.chrome.com/devtools/docs/console-api#consoletimelabel
I fine with removing it as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Well, in that case, I'm fine with leaving it. If it's good enough for Chrome docs, it's good enough for me.
Sorry for all the bikeshedding on this. LGTM no matter which way you decide to go with it (leave it, remove it, change it as described).