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

Is 'console.time' in nodejs synchronous or async?

我正在尝试为某事记录时间。一般代码如下所示:

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();
    }
});

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

根据console.time and console.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);
};

他们只是根据标签存储开始时间,并计算自标签计时以来经过的时间。

它们不会异步执行任何操作。

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