使用 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')