I need to measure the performance overhead of additional Javascript event bindings (using jQuery live), the overhead would probably increase CPU load and be very hard to notice from execution time profiling.
How can I measure the CPU load differences between two different versions of a Javascript application?
Another option for analysis is dynaTrace Ajax edition. Resig has a quick overview of it here. It's specific to IE (but...that's the one with the worst performance in most cases so...)
Take a look, all the suggestions here are great, if you're looking at IE issues (some intranet apps are locked down to it) then dynaTrace is an excellent and still free tool.
The Chrome dev tools are great, but since Chrome is not a browser you ever have to worry about as far as JS performance, and it optimizes things a lot, it doesn't help much with finding bottlenecks of other browsers. IE 8 has dev tools that let you profile, so you might find that useful, besides the usual Firebug profiler.
But regarding your situation, let me say that just binding an event doesn't result in much CPU load, more of a memory issue, but you shouldn't have to worry unless you're doing something out of the ordinary on your page.
Also if you're concerned in particular about the jQuery.live function, let me quickly explain how it works:
Let's say you do $('#linksWrap a').live('click', fn);
#linkswrap
.#linkswrap
.fn
within the context of the link that was clickedSo as you see, it's actually pretty efficient. The browser only attaches one event, so memory usage is low, and it also doesn't need to constantly check for new elements, it uses event bubbling in a cool way.
In fact one might argue, that if you are attaching thousands of events to a page, the .live method might be more efficient, assuming you're using good selectors. (e.g. .something .foo .bar.baz
requires a lot of traversal and bubbling, but #parentOfTheLinks a.links
will be quick)
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