- Runs performance checks on a given function. Reports the average milliseconds
needed to execute a given function over a given number of executions. For example:
Input:
f = function() {
i=50000;
while(i>0) i--;
}
t = new Profiler(f);
t.multiPass(10);
Output:
-------PROFILER----------------------------------------------
function () {
i = 50000;
while (i > 0) {
i--;
}
}
-------PROFILER----------------------------------------------
Type of profile: runOnce
Average execution time: 146ms
Average calculated from 10 pass(es)
-------PROFILER----------------------------------------------
- The Profiler.multiPass() method allows you to run looped code in a regular for loop or a
reverse while loop, as well:
t.multiPass(10,"forLoop",100); //execute f() in a for loop of 100 iterations 10 times
t.multiPass(5,"reverseWhile",200); //execute f() in a reverse while loop of 200 iterations 5 times
- The Profiler will automatically store and average results for different types of
executions. For example, if you do a multi-pass operation for 300 times, the Profiler
will give you the average of all three hundred executions. If you do a multi-pass operation
with a loop, Profiler will store results for that loop / iteration combination discretely
from other loop/iteration combinations. For example,
t.multiPass(10,"forLoop",100);
will necessarily have different results from
t.multiPass(10,"forLoop",200);
as the latter loops 100 more times than the former. Profiler recognizes this and stores
their results discretely.