![]() |
|
Navigation |
Synopsis Measure and report the execution time of name:void-closure pairs
Function
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; okWe 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)
![]() |