我怎样才能计算出有多少时间的函数需要在jQuery的? [英] How can I calculate how much time a function takes in jQuery?

查看:118
本文介绍了我怎样才能计算出有多少时间的函数需要在jQuery的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我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);
}

这篇关于我怎样才能计算出有多少时间的函数需要在jQuery的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆