mirror of
https://github.com/nodejs/node.git
synced 2026-10-14 10:26:26 -04:00
console: sub-millisecond accuracy for console.time
This makes the output of console.timeEnd in line with major browsers. PR-URL: https://github.com/nodejs/node/pull/3166 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Trevor Norris <trev.norris@gmail.com>
This commit is contained in:
1 parent
642928b502
commit
419f7d4726
3 files changed
+9
-8
No files matched your search
+4
-3
@@ -56,7 +56,7 @@ Console.prototype.dir = function(object, options) {
|
||||
|
||||
|
||||
Console.prototype.time = function(label) {
|
||||
this._times.set(label, Date.now());
|
||||
this._times.set(label, process.hrtime());
|
||||
};
|
||||
|
||||
|
||||
@@ -65,8 +65,9 @@ Console.prototype.timeEnd = function(label) {
|
||||
if (!time) {
|
||||
throw new Error('No such label: ' + label);
|
||||
}
|
||||
var duration = Date.now() - time;
|
||||
this.log('%s: %dms', label, duration);
|
||||
const duration = process.hrtime(time);
|
||||
const ms = duration[0] * 1000 + duration[1] / 1e6;
|
||||
this.log('%s: %sms', label, ms.toFixed(3));
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user