Wolfram Research

Function Repository Resource:

EvaluateBenchmark

Source Notebook

Measure the evaluation timings of a function on a given set of inputs

Contributed by: Taliesin Beynon

ResourceFunction["EvaluateBenchmark"][f,g,{n1,n2,}]

gives {{n1,t1},{n2,t2},}, where ti is the time taken to evaluate f on the input g[ni], as measured by RepeatedTiming.

ResourceFunction["EvaluateBenchmark"][f,g]

chooses the ni adaptively by observing the execution of f.

Details and Options

ResourceFunction["EvaluateBenchmark"] effectively uses Monitor.
ResourceFunction["EvaluateBenchmark"] takes the following options:
TimeConstraint 10.0 maximum time to run tests

Examples

Basic Examples

Get the timings for Inverse of random matrices:

In[1]:=
ResourceFunction["EvaluateBenchmark"][Inverse, RandomReal[1, {#, #}] &, Range[50, 100]]
Out[1]=

View a plot of the results:

In[2]:=
ResourceFunction["BenchmarkPlot"][%]
Out[2]=

Options

TimeConstraint

By default, the total time is limited to 10 seconds:

In[3]:=
ResourceFunction["EvaluateBenchmark"][Pause, #/100 &]
Out[3]=

Allow more time for benchmarking:

In[4]:=
ResourceFunction["EvaluateBenchmark"][Pause, #/100 &, TimeConstraint -> 30]
Out[4]=

Measure all inputs regardless of how long it takes:

In[5]:=
ResourceFunction["EvaluateBenchmark"][Pause, #/100 &, Range[20], TimeConstraint -> Infinity]
Out[5]=
In[6]:=
ResourceFunction["BenchmarkPlot"][%]
Out[6]=

Requirements

Wolfram Language 11.3 (March 2018) or above

Resource History

See Also

License Information