<div class="intro">
<p>This example shows using the Profiler on all methods in an object. It uses the <code>Y.DOM</code> object
as the object to be profiled.</p>
</div>
<div class="example">
{{>profiler-object-example-source}}
</div>
<h2 class="first">Object Profiling Example</h2>
<p>To illustrate using the Profiler on objects, the <code>Y.DOM</code> and <code>Y.Node</code> objects are registered for profiling. This means
that all of the methods on these objects are being profiled. To
illustrate their use, a number of demo elements are added to the markup:</p>
```
<div class="bar">div class="bar"</div>
<div class="bar-baz">div class="bar-baz"</div>
<div class="bar ">div class="bar "</div>
<div class=" bar ">div class=" bar "</div>
<div class="bar baz">div class=" bar baz"</div>
<div class="bar2 baz">div class=" bar2 baz"</div>
<div class="foo">div class="foo"</div>
<div class="foo" id="bar">div class="foo" id="bar"</div>
<div class="foo bar baz">div class="foo bar baz"</div>
<p class="bar">p class="bar"</p>
<button id="demo-run">run</button>
```
<p>The button is used to run the example. The function being called when the button is clicked is assigned by first
retrieving a <code>Node</code> instance for the button and then using the <code>on</code> method:</p>
```
<script>
YUI().use('node', 'profiler', function (Y) {
Y.one('#demo-run').on('click', function(){
var results = Y.Node.all('.bar');
results.addClass("newclass");
var report = Y.Profiler.getFullReport(function(data){
return data.calls > 0;
});
//output results
var msg = "";
for (var func in report){
msg += (func + "(): Called " + report[func].calls + " times. Avg: " +
report[func].avg + ", Min: " + report[func].min + ", Max: " + report[func].max) + "\\n";
}
alert(msg);
});
});
</script>
```
<p>The function begins be registering <code>Y.DOM</code> and <code>Y.Node</code> with the Profiler. Note that since these objects don't
exist in the global scope, the second argument is necessary for <code>registerObject()</code>. Then, the <code>Y.Node.all()</code>
method is called to retrieve nodes for each element with a class of <code>bar</code>. The result of this operation is a <code>NodeList</code>
object, on which the <code>addClass()</code> method is called. After that, the full report is returned and the objects are unregistered. The last
step is to output all of the information that was collected. Even though there's only two methods called explicitly in this example,
the profiled data indicates that several other methods on <code>Y.DOM</code> and <code>Y.Node</code> were called internally to accomplish the
tasks.</p>
<h2>Complete Example Source</h2>
```
{{>profiler-object-example-source}}
```