是否可以将console.time()
结果写入变量?
console.time('It\'s saved!');
fn();
var a = console.timeEnd('It\'s saved!');
console.log(a) // => It's saved!: 16ms
答案 0 :(得分:4)
不,但您可以使用window.performance.now()
代替
var t0 = performance.now();
doSomething();
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")