How to measure code execution time in VBScript or JavaScript?

前端 未结 7 1659
野趣味
野趣味 2020-12-06 05:23

What is a good way to measure code execution time in VBScript?

Or failing that how to do it in JavaScript?

7条回答
  •  南笙
    南笙 (楼主)
    2020-12-06 06:01

    d = new Date();
    x = 0;
    for (i = 0; i < 1e7; ++i) { x += i; }
    d2 = new Date();
    d2 - d
    
    12296
    

    Use the Date object, which returns a valueOf() in milliseconds since Jan 1 1970. You can then subtract times to get elapsed time in milliseconds.

提交回复
热议问题