以秒为单位的控制台时间
Console time in second
是否可以将控制台时间的操作时间设置为秒而不是毫秒?
这是我的代码:
console.log('start load cache');
console.time('cache load ok executed in')
// my loading from mongo
console.timeEnd('cache load ok executed in')
我得到的:
start load cache
cache load ok executed in: 47245.049ms
我想要什么:
start load cache
cache load ok executed in: 47.245s
谢谢!
console.time 不会解决这个问题,但您始终可以自己做:
console.log('start load cache');
const before = Date.now();
// my loading from mongo
const after = Date.now();
console.log('cache load ok executed in', (after - before) / 1000);
您可以创建自定义函数并按如下方式使用它。
var getExecutionTime = function (fn) {
var from = Date.now();
fn();
var to = Date.now();
return to - from;
}
var execTime = getExecutionTime(function(){
// my loading from mongo
});
console.log("execution time in milisecond:", execTime/1000);
是否可以将控制台时间的操作时间设置为秒而不是毫秒?
这是我的代码:
console.log('start load cache');
console.time('cache load ok executed in')
// my loading from mongo
console.timeEnd('cache load ok executed in')
我得到的:
start load cache
cache load ok executed in: 47245.049ms
我想要什么:
start load cache
cache load ok executed in: 47.245s
谢谢!
console.time 不会解决这个问题,但您始终可以自己做:
console.log('start load cache');
const before = Date.now();
// my loading from mongo
const after = Date.now();
console.log('cache load ok executed in', (after - before) / 1000);
您可以创建自定义函数并按如下方式使用它。
var getExecutionTime = function (fn) {
var from = Date.now();
fn();
var to = Date.now();
return to - from;
}
var execTime = getExecutionTime(function(){
// my loading from mongo
});
console.log("execution time in milisecond:", execTime/1000);