nodejs中的'console.time'是同步还是异步?

cod*_*man 3 javascript console node.js

我正在尝试记录时间.一般代码如下所示:

var stream = db.call.stream();
stream.on('data', function () {
    if (first) {
        console.time('doSomething');
    }
    stream.pause();
    doSomethingWithData(data);
    if (stopCondition) {
        console.timeEnd('doSomething');
        done();
    } else {
        stream.resume();
    }
});
Run Code Online (Sandbox Code Playgroud)

我想知道调用console.time是阻塞还是异步?我在文档中找不到这个.

the*_*eye 5

据的源代码console.timeconsole.timeEnd,

Console.prototype.time = function(label) {
  this._times[label] = Date.now();
};


Console.prototype.timeEnd = function(label) {
  var time = this._times[label];
  if (!time) {
    throw new Error('No such label: ' + label);
  }
  var duration = Date.now() - time;
  this.log('%s: %dms', label, duration);
};
Run Code Online (Sandbox Code Playgroud)

它们只是根据标签存储起始时间并计算自标签定时以来经过的时间.

他们不会异步做任何事情.

注意:在node.js中,如果函数是异步的,它将接受callback作为参数之一.