hi i am using jquery .
i have a check box click event
jQuery('.btn-check-box').click(function () {
//code goes here .
});
the problem is the click event takes considerable time to complete.some times the browser gets stuck. so i want to change the code inside the function and reduce the completion time .
now i want to get my current click event completion time . then make changes to the code and again check the completion time .
so i can optimize my code according to the completion time .
is there any way to check an events completion time . please help. thanks in advance.
Pass event as argument.
var createdTime;
jQuery('.btn-check-box').click(function(e){
createdTime = e.timeStamp;
}).done(function(){ calculate time difference });
if you will use console.log(e)
then it will show you that jQuery already passing timestamp when event is triggered.
so now you need to find a way when even is getting done so .done()
jQuery method will help you.
In side .done() you can also get same e.timestamp
and do some math on to get your desired out put in second, minutes or anything.
Like SrinivasR said, finish time - start time.
jQuery('.btn-check-box').click(function () {
var t0 = (new Date()).getTime();
//code goes here
console.log("Event took",(new Date()).getTime() - t0, "ms to complete.");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With