Navigation
Synopsis Measure and report the execution time of name:void-closure pairs
Function
  1. map[str,num] benchmark(map[str, void()] Cases)
  2. map[str,num] benchmark(map[str, void()] Cases, int (void ()) duration)
Usage import util::Benchmark;
Description Given is a map that maps strings (used as label to identify each case) to void-closures that execute the code to be benchmarked. An optional duration argument can be used to specify the function to perform the actual measurement. By default the function realTime is used. A map of labels and durations is returned.
Examples We use the factorial function described in Recipes:Factorial as example:
rascal>import util::Benchmark;
ok
rascal>import demo::basic::Factorial;
ok
We measure two calls to the factorial function with arguments 100, respectively, 200 (using by default realkTime that returns milliseconds):
rascal>benchmark( ("fac10" : void() {fac(100);}, "fac20" : void() {fac(200);}) );
map[str, num]: ("fac20":3,"fac10":1)
We can do the same using userTime that returns nanoseconds:
rascal>benchmark( ("fac10" : void() {fac(100);}, "fac20" : void() {fac(200);}), userTime );
map[str, num]: ("fac20":1714000,"fac10":804000)
Is this page unclear, or have you spotted an error? Please add a comment below and help us to improve it. For all other questions and remarks, visit ask.rascal-mpl.org.