How do you performance test JavaScript code?

前端 未结 22 1139
难免孤独
难免孤独 2020-11-22 04:18

CPU Cycles, Memory Usage, Execution Time, etc.?

Added: Is there a quantitative way of testing performance in JavaScript besides just perception of how fast the code

22条回答
  •  悲&欢浪女
    2020-11-22 04:45

    We can always measure time taken by any function by simple date object.

    var start = +new Date();  // log start timestamp
    function1();
    var end =  +new Date();  // log end timestamp
    var diff = end - start;
    

提交回复
热议问题