我正在尝试记录时间。通用代码如下所示:
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
和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
作为参数之一。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句