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()
方法的字符串必须匹配(以 使计时器按预期完成)。