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

Revert "console: rename argument of time and timeEnd" #3590

Closed
Show file tree
Hide file tree
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
8 changes: 4 additions & 4 deletions doc/api/console.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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(timerName)
### console.time(label)

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
[`console.timeEnd()`](#console_console_timeend_label) to stop the timer and
output the elapsed time in milliseconds. Timer durations are accurate to the
sub-millisecond.

### console.timeEnd(timerName)
### console.timeEnd(label)

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.

Example:
Expand Down
12 changes: 6 additions & 6 deletions lib/console.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ Console.prototype.dir = function(object, options) {
};


Console.prototype.time = function(timerName) {
this._times.set(timerName, process.hrtime());
Console.prototype.time = function(label) {
this._times.set(label, process.hrtime());
};


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


Expand Down