Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i compute the Time For execution of Each Jquery Statement

Right now I am using jQuery completely for my project (ajax, validations). But I guess due to my statements I assume that it is taking more time and how can I optimize the time for execution of each statement? Say for example I have seen some posts in Stackoverflow saying this statement:

$("div#mydialog").bind('Dialogclose',function(){});

is much slower than this:

$("#mydialog").bind('Dialogclose',function(){});

How can I attain this conclusion? Do I have S Tools for this? How can I optimise the statements in jQuery? What are the best practices to be used in jQuery?

like image 358
Someone Avatar asked Nov 03 '10 20:11

Someone


People also ask

What is the use of each () function in jQuery?

each() jQuery's each() function is used to loop through each element of the target jQuery object — an object that contains one or more DOM elements, and exposes all jQuery functions. It's very useful for multi-element DOM manipulation, as well as iterating over arbitrary arrays and object properties.

How do you know how many times a function is called?

To count how many times a function has been called, declare a count variable outside of the function, setting it to 0 . Inside of the body of the function reassign the variable incrementing it by 1 . The count variable will store the number of function invocations. Copied!

How to delay jQuery execution?

The jQUery delay () method sets a timer to delay the execution of the next item in the queue. Syntax: $(selector). delay (speed, queueName)

How do you iterate through an element in jQuery?

The .each() method is designed to make DOM looping constructs concise and less error-prone. When called it iterates over the DOM elements that are part of the jQuery object. Each time the callback runs, it is passed the current loop iteration, beginning from 0.


2 Answers

Why not use the PROFILE jquery plug-in from plugins.jquery.com, which was made for just this purpose: PROFILE jquery plug-in

like image 78
Michael Goldshteyn Avatar answered Oct 03 '22 07:10

Michael Goldshteyn


Try running your pages with the FireQuery FireFox extension.

http://firequery.binaryage.com/

FireQuery allows you to inject jQuery Lint (https://github.com/jamespadolsey/jQuery-Lint) into a page, giving you information on jQuery errors and incorrect usage.

You can also use a JavaScript profiler, such as FireBug in FireFox, the IE Developer Console in IE8 or higher, Developer Tools in Chrome, etc. This will give you execution times in each browser which can then be optimized.

like image 20
James Kovacs Avatar answered Oct 03 '22 06:10

James Kovacs