How do I measure the execution time of JavaScript code with callbacks?

前端 未结 10 1511
臣服心动
臣服心动 2020-11-30 16:28

I have a piece of JavaScript code that I am executing using the node.js interpreter.

for(var i = 1; i <         


        
10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-11-30 16:38

    Invoking console.time('label') will record the current time in milliseconds, then later calling console.timeEnd('label') will display the duration from that point.

    The time in milliseconds will be automatically printed alongside the label, so you don't have to make a separate call to console.log to print a label:

    console.time('test');
    //some code
    console.timeEnd('test'); //Prints something like that-> test: 11374.004ms
    

    For more information, see Mozilla's developer docs on console.time.

提交回复
热议问题