On 6/5/2011 9:17 AM, LG Faulty wrote:
What would a better/lighter-weight/less-intrusive way of implementing
a javascript profiler be?
Any hints would be much appreciated.
I haven't used it, but I've seen the YUI profiler mentioned a number of times:
http://developer.yahoo.com/yui/3/profiler/
I'd take a look at how it does the function/method wrapping with the timing
code.
Also in your code you are hard coding 4 arguments when you are "forwarding" the
call through your wrapper into the function being called. You should also look at the
apply method of a function as it allows you to pass along the parent object as a context
for the function to run within and the function arguments as an array:
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/apply
Enjoy,
Danilo Celic
Many thanks,
Luigi
-- for reference, part of ''profiling framework''
profiler.add = function(target) {
for(var elm in target) {
if (typeof target[elm] == "function"&& target[elm].__noprofile
==
undefined) {
target[elm] = profiler.wrap(target, elm)
target[elm].__timespent = 0
}
if (target.propertyIsEnumerable(elm)) {
profiler.add(target[elm])
}
}
}
profiler.wrap = function(obj, prop) {
var oldf = obj[prop]
return function() {
var t_start = new Date().getTime();
var retval = oldf(arguments[0], arguments[1], arguments[2],
arguments[3]) // 4 for now
obj[prop].__timespent += new Date().getTime() - t_start
return retval
}
}
// to profile:
profiler.add(faultylabs.u128)
library.runBenchmark()
profiler.report(faultylabs.u128, document.getElementById('rptdiv'))
--
To view archived discussions from the original JSMentors Mailman list:
http://www.mail-archive.com/[email protected]/
To search via a non-Google archive, visit here:
http://www.mail-archive.com/[email protected]/
To unsubscribe from this group, send email to
[email protected]