Performance
About
This class can be used to test the performance of code.
API
constructor()
cs.js.Performance.new(func : Callable { ; count : Integer { ; thisObj : Object { ; parameters : Collection }}})
Creates an object whose .alert()
and .timePerExecution()
functions will execute func.apply(thisObj; parameters)
count times.
If count is not passed or is <= 0, it defaults to 1000.
If thisObj and/or parameters are passed, they are passed to func.apply()
.
Examples
$func:=Formula($1+" "+This.name+"!")
$p:=cs.js.Performance.new(\
$func; \
10000; \
New object("name"; "Laurent"); \
New collection("Hello"))
$p.alert()
// See the Functor.apply() example for the definition of CollectionOp
$func:=cs.CollectionOp.new("sum")
$p:=cs.js.Performance.new(\
$func; \
10000; \
Null; \
New collection(1; 2; 3))
$timing:=$p.timePerExecution()
.alert()
.alert()
Shows an alert with the time it took to execute the Callable passed to the constructor.
In the example given in the constructor, the alert will show something like:
10,000 iterations
0.0056 ms per iteration
.timePerExecution()
.timePerExecution() : Real
Returns the time it took to execute the Callable passed to the constructor the configured number of times, divided by the number of iterations.