From 14f45bb8efe70d4a093469f6978e8e0255a132e1 Mon Sep 17 00:00:00 2001 From: Leah Lundqvist Date: Mon, 30 Nov 2020 20:01:11 +0100 Subject: [PATCH] fast.v: average measure results, discarding extremes (#7052) good work --- cmd/tools/fast/fast.v | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cmd/tools/fast/fast.v b/cmd/tools/fast/fast.v index 3c257059dc..59df0f64c9 100644 --- a/cmd/tools/fast/fast.v +++ b/cmd/tools/fast/fast.v @@ -110,7 +110,19 @@ fn measure(cmd string, description string) int { exec(cmd) } println(' Building...') - sw := time.new_stopwatch({}) - exec(cmd) - return int(sw.elapsed().milliseconds()) + mut runs := []int{} + for r in 0 .. 5 { + println(' Sample ${r+1}/5') + sw := time.new_stopwatch({}) + exec(cmd) + runs << int(sw.elapsed().milliseconds()) + } + // discard lowest and highest time + runs.sort() + runs = runs[1..4] + mut sum := 0 + for run in runs { + sum += run + } + return int(sum / 3) }