Skip to main content

bench

Jump to function (2)

bench/defbench#

(defbench bench-name & body)

Defines a benchmark function.

The body is timed, not asserted. An optional option map may follow the name: :revs (calls per measured iteration), :iterations (measured iterations), :warmup (unmeasured iterations first). Anything omitted falls back to the default. A run-wide option of the same name, such as a phel bench --revs flag, overrides what the benchmark asks for.

Metadata attached to bench-name is forwarded to the defined function, so ^:slow and ^{:tags [:io]} work here exactly as they do on deftest.

Example:

(defbench bench-sum {:revs 10000}
  (reduce + 0 (range 100)))

bench/run-benchmarks#

(run-benchmarks options & namespaces)

Runs every defbench in the given namespaces and prints a table.

Recognized option keys: :revs, :iterations, :warmup (each overrides the per-benchmark option of the same name), :filter (substring match against the benchmark name), :store (path to write the results to as a baseline), :ref (path to a stored baseline to compare against), and :tolerance (a percentage; when set, a benchmark slower than its baseline by more than this makes the run unsuccessful).

Returns true when the run is within tolerance, which is always the case when no tolerance is set.

Example:

(run-benchmarks {:revs 100} 'my-app.bench)