From 2fa8be21ab0067dba6b687ec29b8547394d719df Mon Sep 17 00:00:00 2001 From: hellerve Date: Wed, 24 Jan 2018 13:28:57 +0100 Subject: [PATCH] core: added set-min-runs! to Bench to be able to adjust the minimum number of runs --- core/Bench.carp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/core/Bench.carp b/core/Bench.carp index 38c3f02d..a5e3b111 100644 --- a/core/Bench.carp +++ b/core/Bench.carp @@ -4,6 +4,13 @@ (register get-time-elapsed (Fn [] Double)) (defmodule Bench + (def min-runs 50) + + (defn set-min-runs! [n] + ; / 2 because we run it twice per benchmarking run, + ; but this is an implementation detail + (set! &min-runs (/ n 2))) + (defn get-unit [n] (cond (< n 1000.0) (String.append (Double.str n) @"ns") @@ -34,9 +41,9 @@ (defn get-samples [f n] (let [zero 0.0 - samples (Array.replicate 50 &zero)] + samples (Array.replicate min-runs &zero)] (do - (for [i 0 50] + (for [i 0 min-runs] (Array.aset! &samples i (Double./ (ns-iter-inner f (Double.to-int n)) n))) (Statistics.summary &(Statistics.winsorize &samples 5.0)))))