Browse Source

console: use 'label' argument for time and timeEnd

Turns out the argument is actually called label in the console spec,
while being wrongly named on MDN. This reverts commit
8c043c1245.

MDN has been updated in:

https://developer.mozilla.org/en-US/docs/Web/API/Console/timeEnd$compare?locale=en-US&to=947893&from=918571
https://developer.mozilla.org/en-US/docs/Web/API/Console/time$compare?locale=en-US&to=947891&from=896987

PR-URL: https://github.com/nodejs/node/pull/3590
Reviewed-By: targos - Michaël Zasso <mic.besace@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
process-exit-stdio-flushing
Roman Reiss 9 years ago
parent
commit
9aee2c0e26
  1. 8
      doc/api/console.markdown
  2. 12
      lib/console.js

8
doc/api/console.markdown

@ -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. - `colors` - if `true`, then the output will be styled with ANSI color codes.
Defaults to `false`. Colors are customizable, see below. Defaults to `false`. Colors are customizable, see below.
### console.time(timerName) ### console.time(label)
Starts a timer that can be used to compute the duration of an operation. Timers 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 are identified by a unique name. Use the same name when you call
[`console.timeEnd()`](#console_console_timeend_timername) to stop the timer and [`console.timeEnd()`](#console_console_timeend_label) to stop the timer and
output the elapsed time in milliseconds. Timer durations are accurate to the output the elapsed time in milliseconds. Timer durations are accurate to the
sub-millisecond. sub-millisecond.
### console.timeEnd(timerName) ### console.timeEnd(label)
Stops a timer that was previously started by calling Stops a timer that was previously started by calling
[`console.time()`](#console_console_time_timername) and prints the result to the [`console.time()`](#console_console_time_label) and prints the result to the
console. console.
Example: Example:

12
lib/console.js

@ -55,19 +55,19 @@ Console.prototype.dir = function(object, options) {
}; };
Console.prototype.time = function(timerName) { Console.prototype.time = function(label) {
this._times.set(timerName, process.hrtime()); this._times.set(label, process.hrtime());
}; };
Console.prototype.timeEnd = function(timerName) { Console.prototype.timeEnd = function(label) {
var time = this._times.get(timerName); var time = this._times.get(label);
if (!time) { if (!time) {
throw new Error('No such timer name: ' + timerName); throw new Error('No such label: ' + label);
} }
const duration = process.hrtime(time); const duration = process.hrtime(time);
const ms = duration[0] * 1000 + duration[1] / 1e6; const ms = duration[0] * 1000 + duration[1] / 1e6;
this.log('%s: %sms', timerName, ms.toFixed(3)); this.log('%s: %sms', label, ms.toFixed(3));
}; };

Loading…
Cancel
Save