您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

JavaScript如何测量函数执行所花费的时间

JavaScript如何测量函数执行所花费的时间

var t0 = performance.Now()

doSomething()   // <---- The function you're measuring time for

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

:需要导入performance

console.time('someFunction')

someFunction() // Whatever is timed goes between the two "console.time"

console.timeEnd('someFunction')

: 传递给time()timeEnd()方法的字符串必须匹配(以 使计时器按预期完成)。

javascript 2022/1/1 18:17:15 有485人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶