Theodore Theodore - 6 months ago 9
Javascript Question

How can I calculate how much time a function takes in jQuery?

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

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?

Answer

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