Commit 6281a8be authored by Han-Wen Nienhuys's avatar Han-Wen Nienhuys

Compute stddev, median and 10/90 percentile stats as well.

parent 8988ee1f
...@@ -4,13 +4,15 @@ package main ...@@ -4,13 +4,15 @@ package main
// in parallel. This is useful for benchmarking purposes. // in parallel. This is useful for benchmarking purposes.
import ( import (
"github.com/hanwen/go-fuse/fuse" "encoding/line"
"os"
"flag" "flag"
"time"
"fmt" "fmt"
"encoding/line" "github.com/hanwen/go-fuse/fuse"
"math"
"os"
"runtime" "runtime"
"sort"
"time"
) )
func main() { func main() {
...@@ -41,25 +43,58 @@ func main() { ...@@ -41,25 +43,58 @@ func main() {
files = append(files, string(l)) files = append(files, string(l))
} }
tot := 0.0
totalRuns := *runs + 1 totalRuns := *runs + 1
results := make([]float64, 0)
for j := 0; j < totalRuns; j++ { for j := 0; j < totalRuns; j++ {
result := BulkStat(*threads, files) result := BulkStat(*threads, files)
if j > 0 { if j > 0 {
tot += result results = append(results, result)
} else { } else {
fmt.Println("Ignoring first run to preheat caches.") fmt.Println("Ignoring first run to preheat caches.")
} }
if j < totalRuns-1 { if j < totalRuns-1 {
fmt.Printf("Sleeping %.2f seconds\n", *sleepTime) fmt.Printf("Sleeping %.2f seconds\n", *sleepTime)
time.Sleep(int64(*sleepTime * 1e9)) time.Sleep(int64(*sleepTime * 1e9))
} }
} }
fmt.Printf("Average of %d runs: %f ms\n", *runs, tot/float64(*runs)) Analyze(results)
}
func Analyze(times []float64) {
sorted := sort.Float64Array(times)
sorted.Sort()
tot := 0.0
for _, v := range times {
tot += v
}
n := float64(len(times))
avg := tot / n
variance := 0.0
for _, v := range times {
variance += (v - avg)*(v - avg)
}
variance /= n
stddev := math.Sqrt(variance)
median := sorted[len(times)/2]
perc90 := sorted[int(n * 0.9)]
perc10 := sorted[int(n * 0.1)]
fmt.Printf(
"%d samples\n" +
"avg %.2f ms 2sigma %.2f " +
"median %.2fms\n" +
"10%%tile %.2fms, 90%%tile %.2fms\n",
len(times), avg, 2*stddev, median, perc10, perc90)
} }
// Returns milliseconds.
func BulkStat(parallelism int, files []string) float64 { func BulkStat(parallelism int, files []string) float64 {
todo := make(chan string, len(files)) todo := make(chan string, len(files))
dts := make(chan int64, parallelism) dts := make(chan int64, parallelism)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment