写控制台.时间结果变量
Write console.time result to variable
是否可以将console.time()
结果写入变量?
console.time('It''s saved!');
fn();
var a = console.timeEnd('It''s saved!');
console.log(a) // => It's saved!: 16ms
不可以,但是您可以使用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/我知道这个问题有点老了,但现在你可以在Node.js中使用性能Api:
const {performance} = require('perf_hooks');
const start = performance.now();
fn();
const end = performance.now();
console.log(`${end - start}ms`);
或使用timerify()
:
const {
performance,
PerformanceObserver
} = require('perf_hooks');
function fn() {
// some stuff here
}
const wrapped = performance.timerify(fn);
const obs = new PerformanceObserver((list) => {
console.log(list.getEntries()[0].duration);
obs.disconnect();
});
obs.observe({ entryTypes: ['function'] });
// A performance timeline entry will be created
wrapped();
注意:性能api是在Node v8.5.0中添加的
相关文章:
- 将地理编码结果转换为php变量以发布到mysql数据库
- 存储区向变量返回了结果
- 如何将解析云代码的query.count结果保存在变量中
- 设置为负数的变量计算结果为true
- 向模板实例变量传递调用方法调用的结果时出现异常
- 将函数结果传递给Javascript中的另一个函数变量
- MongoDB MonkAPI根据数据库请求之外可用的查找结果设置变量
- 将ajax请求结果分配给jquery函数中的变量
- 如何在javascript变量中获取php文件的结果
- 使用动态变量名更新JSON中的结果
- 将结果从javascript发布到变量
- Javascript我可以't达到函数中的结果变量
- 在不使用200行var的情况下,在结果字段中添加顺序命名的变量?[PDF表格]
- 使用passthrough将ajax结果中的变量发送到php
- 如何从批处理文件调用一个带有2个参数的java脚本函数,并将结果返回到环境变量
- 调用函数而不将其结果分配给变量
- 用javascript添加变量作为随机生成的结果编号
- 在jQuery函数中将结果从AJAX返回到PHP变量
- 使用变量和获取输入值时,substr()的结果不同
- 定义的变量结果为null