<script>
YUI().use('event', 'profiler', function (Y) {
//object with method to profile
factorial : function (num){
if (num > 1) {
return num * Y.example.profiler.MathHelper.factorial(num-1);
} else {
return 1;
}
}
};
//register the function
Y.Profiler.registerFunction("Y.example.profiler.MathHelper.factorial", Y.example.profiler.MathHelper);
Y.on("domready", function (){
var calls = Y.Profiler.getCallCount("Y.example.profiler.MathHelper.factorial");
var max = Y.Profiler.getMax("Y.example.profiler.MathHelper.factorial");
var min = Y.Profiler.getMin("Y.example.profiler.MathHelper.factorial");
var avg = Y.Profiler.getAverage("Y.example.profiler.MathHelper.factorial");
var msg = "Method Y.example.profiler.MathHelper was run " + calls + "times.\n" +
"The average time was " + avg + "ms.\n" +
"The max time was " + max + " ms.\n" +
"The min time was " + min + " ms.";
alert(msg);
});
});
</script>