js timeend
The console.time
and console.timeEnd
methods allow developers to time any routine and get a duration in milliseconds. Since JavaScript performance is becoming increasingly important, it's good to know basic techniques for benchmarking routines. One of the most basic benchmarking tools is console.time
with console.timeEnd
.
console.time
和console.timeEnd
方法使开发人员可以为任何例程计时,并获得持续时间(以毫秒为单位)。 由于JavaScript性能变得越来越重要,因此最好了解基准测试例程的基本技术。 一个最基本的基准测试工具是console.time
与console.timeEnd
。
console.time
starts the time and console.timeEnd
stops the timer and spits out the duration:
console.time
启动时间, console.timeEnd
停止计时器并吐出持续时间:
// Kick off the timer
console.time('testForEach');
// (Do some testing of a forEach, for example)
// End the timer, get the elapsed time
console.timeEnd('testForEach');
// 4522.303ms (or whatever time elapsed)
Passing a timer name as the first argument allows you to manage concurrent timers. The console.timeEnd
call immediately spits out the elapsed time in milliseconds.
通过将计时器名称作为第一个参数传递,可以管理并发计时器。 console.timeEnd
调用会立即吐出经过的时间(以毫秒为单位)。
There are more advanced techniques for performance testing and benchmarking but console.time
/timeEnd
provide a quick manual method for speed testing!
有更多用于性能测试和基准测试的高级技术,但是console.time
/ timeEnd
提供了一种快速的手动方法来进行速度测试!
翻译自: https://davidwalsh.name/console-time
js timeend