将console.time结果写入变量

时间:2015-07-16 19:10:49

标签: javascript node.js

是否可以将console.time()结果写入变量?

console.time('It\'s saved!');
fn();
var a = console.timeEnd('It\'s saved!');
console.log(a) // => It's saved!: 16ms

1 个答案:

答案 0 :(得分:4)

不,但您可以使用window.performance.now()代替

var t0 = performance.now();
doSomething();
var t1 = performance.now();
console.log("Call to doSomething took " + (t1 - t0) + " milliseconds.")

http://jsfiddle.net/8Lt250wa/