How do you performance test JavaScript code?

前端 未结 22 1330
难免孤独
难免孤独 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:50

    This is a good way of collecting performance information for the specific operation.

    start = new Date().getTime(); 
    for (var n = 0; n < maxCount; n++) {
    /* perform the operation to be measured *//
    }
    elapsed = new Date().getTime() - start;
    assert(true,"Measured time: " + elapsed);
    

提交回复
热议问题