我怎样才能计算出有多少时间的函数需要在jQuery的?有多少、计算出、函数、时间

2023-09-11 00:55:21 作者:焚心劫

我jQuery的功能;例如A(),B()和C() 每个功能使得一些Ajax调用不同的网站。

I have jQuery functions; e.g A(), B() and C() Each function makes some Ajax calls to different sites.

我要计算多少时间才能运行的每个功能(我猜毫秒) 我只是想测试我的code在长期循环和不同的现代浏览器(Safari /铬/ IE10 / Mozilla的)。 更具体地讲,我要计算多少时间才能通过各个Ajax请求的回调(这也是该函数结束正确的时间?) 我怎么可能做到这一点?

I want to calculate how much time it takes to run each function (I guess in milliseconds) I just want to test my code in long loops and in different modern browsers (Safari/Chrome/IE10/Mozilla). More specifically, I want to calculate how much time it takes to take a callback from each Ajax request (this is also the time that the function ends right?) How might I achieve this?

推荐答案

您可以从日期对象获得以毫秒为单位的时间。

You could get the time in milliseconds from the date object.

var start = new Date().getTime();

A();

function AJAXSuccessFunction() {
    console.log(new Date().getTime() - start);
}