1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

fast.v: average measure results, discarding extremes (#7052)

good work
This commit is contained in:
Leah Lundqvist 2020-11-30 20:01:11 +01:00 committed by GitHub
parent ff42572e93
commit 14f45bb8ef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)
}