function MyClass() {
this.foo();
}
MyClass.prototype.foo = function foo() {
var i;
for (i = 0; i < 100; i++) {
document.createElement("div");
}
this.bar();
};
MyClass.prototype.bar = function bar() {
var i;
for (i = 0; i < 100; i++) {
document.createElement("div");
}
};
obj = {
funcA: function funcA() {
var i;
for (i = 0; i < 10; i++) {
this.funcB();
}
},
funcB: function funcB() {
var i, c;
for (i = 0; i < 10; i++) {
c = new MyClass();
c.bar();
}
}
};
function doSomething() {
var i;
for (i = 0; i < 10; i++) {
obj.funcA();
}
return false;
}
// Instantiate a profiler then register above "doSomthing" function, functions of "obj" and class "MyClass".
var profiler = new JsProfiler();
profiler.registerFunction(window, "doSomething", "window");
profiler.registerClass(window, "MyClass");
profiler.registerObject(obj, "obj");
// Start profiler, execute some code, then stop it.
profiler.start();
doSomething();
profiler.stop();
// Print results to console at also show them as an HTML table
var results = profiler.getResults();
JsProfiler.HtmlTableGenerator.showTable(results);
JsProfiler.ConsoleTableGenerator.printResults(results);