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

如何测量函数执行所需的时间

如何测量函数执行所需的时间

使用 performance.Now()

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.")

NodeJs:需要导入performance类

使用console.time:(非标准)(生活水平)

console.time('someFunction')

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

console.timeEnd('someFunction')
其他 2022/1/1 18:37:56 有471人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

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

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

请先登录

推荐问题


联系我
置顶