How to calculate the execution time of an async function in JavaScript?

前端 未结 4 671
失恋的感觉
失恋的感觉 2021-01-11 23:01

I would like to calculate how long an async function (async/await) is taking in JavaScript.

One could do:

const asyncFunc =         


        
4条回答
  •  不要未来只要你来
    2021-01-11 23:29

    Consider using perfrmance.now() API

    var time_0 = performance.now();
    function();
    var time_1 = performance.now();
    console.log("Call to function took " + (time_1 - time_0) + " milliseconds.")
    

    As performance.now() is the bare-bones version of console.time , it provide more accurate timings.

提交回复
热议问题