From d3714729acd0a68a5dfcf7d3e517fb4e692faacd Mon Sep 17 00:00:00 2001 From: jaffee Date: Wed, 16 Nov 2016 10:57:54 -0600 Subject: [PATCH] add fine grained stats within benchmarks --- bench/diagonal.go | 6 ++++++ bench/multidb.go | 6 ++++++ bench/random.go | 6 ++++++ bench/stats.go | 39 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 bench/stats.go diff --git a/bench/diagonal.go b/bench/diagonal.go index 623310243..22e6b5cb9 100644 --- a/bench/diagonal.go +++ b/bench/diagonal.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "context" + "time" ) // DiagonalSetBits sets bits with increasing profile id and bitmap id. @@ -66,10 +67,15 @@ func (b *DiagonalSetBits) Run(agentNum int) map[string]interface{} { results["error"] = fmt.Errorf("No client set for DiagonalSetBits agent: %v", agentNum) return results } + s := NewStats() + var start time.Time for n := 0; n < b.Iterations; n++ { iterID := agentizeNum(n, b.Iterations, agentNum) query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+iterID, b.BaseProfileID+iterID) + start = time.Now() b.cli.ExecuteQuery(context.TODO(), b.DB, query, true) + s.Add(time.Now().Sub(start)) } + AddToResults(s, results) return results } diff --git a/bench/multidb.go b/bench/multidb.go index 46f61cf1c..407b210f9 100644 --- a/bench/multidb.go +++ b/bench/multidb.go @@ -8,6 +8,7 @@ import ( "io/ioutil" "context" + "time" ) // MultiDBSetBits sets bits with increasing profile id and bitmap id. @@ -62,9 +63,14 @@ func (b *MultiDBSetBits) Run(agentNum int) map[string]interface{} { results["error"] = fmt.Errorf("No client set for MultiDBSetBits agent: %v", agentNum) return results } + s := NewStats() + var start time.Time for n := 0; n < b.Iterations; n++ { query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+n, b.BaseProfileID+n) + start = time.Now() b.cli.ExecuteQuery(context.TODO(), "multidb"+strconv.Itoa(agentNum), query, true) + s.Add(time.Now().Sub(start)) } + AddToResults(s, results) return results } diff --git a/bench/random.go b/bench/random.go index 697395918..7c6795408 100644 --- a/bench/random.go +++ b/bench/random.go @@ -8,6 +8,7 @@ import ( "context" "math/rand" + "time" ) // RandomSetBits sets bits randomly and deterministically based on a seed. @@ -84,11 +85,16 @@ func (b *RandomSetBits) Run(agentNum int) map[string]interface{} { results["error"] = fmt.Errorf("No client set for RandomSetBits agent: %v", agentNum) return results } + s := NewStats() + var start time.Time for n := 0; n < b.Iterations; n++ { bitmapID := rng.Int63n(b.BitmapIDRange) profID := rng.Int63n(b.ProfileIDRange) query := fmt.Sprintf("SetBit(%d, 'frame.n', %d)", b.BaseBitmapID+bitmapID, b.BaseProfileID+profID) + start = time.Now() b.cli.ExecuteQuery(context.TODO(), b.DB, query, true) + s.Add(time.Now().Sub(start)) } + AddToResults(s, results) return results } diff --git a/bench/stats.go b/bench/stats.go new file mode 100644 index 000000000..0c1b027cf --- /dev/null +++ b/bench/stats.go @@ -0,0 +1,39 @@ +package bench + +import ( + "time" +) + +type Stats struct { + Min time.Duration + Max time.Duration + Total time.Duration + Num int64 +} + +func NewStats() *Stats { + return &Stats{ + Min: 1<<63 - 1, + } +} + +func (s *Stats) Add(td time.Duration) { + s.Num += 1 + s.Total += td + if td < s.Min { + s.Min = td + } + if td > s.Max { + s.Max = td + } +} + +func (s *Stats) Avg() time.Duration { + return s.Total / time.Duration(s.Num) +} + +func AddToResults(s *Stats, results map[string]interface{}) { + results["min"] = s.Min + results["max"] = s.Max + results["avg"] = s.Avg() +}