Skip to content

Commit

Permalink
added stddev stat
Browse files Browse the repository at this point in the history
  • Loading branch information
Shai Nagar committed May 15, 2021
1 parent 567727a commit b31a385
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
11 changes: 11 additions & 0 deletions internal/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (trw *TextReportWriter) Write(ts pkg.TracerSummary, config *BenchmarkSpec)
trw.writeStatNano2Sec("mean", stats.Mean)
trw.writeStatNano2Sec("median", stats.Median)
trw.writeStatNano2Sec("p90", func() (float64, error) { return stats.Percentile(90) })
trw.writeStatNano2Sec("stddev", stats.StdDev)
trw.writeErrorRateStat("errors", stats.ErrorRate)
trw.writeNewLine()
trw.writer.Flush()
Expand Down Expand Up @@ -80,6 +81,16 @@ func (trw *TextReportWriter) writeStatNano2Sec(name string, f func() (float64, e
}
}

func (trw *TextReportWriter) writeNumericStat(name string, f func() (float64, error)) {
value, err := f()
if err == nil {
trw.writeStatTitle(name)
trw.writer.WriteString(fmt.Sprintf("%.3f\r\n", value))
} else {
trw.writeStatError(name)
}
}

func (trw *TextReportWriter) writeErrorRateStat(name string, f func() float64) {
trw.writeStatTitle(name)

Expand Down
2 changes: 1 addition & 1 deletion internal/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ package internal
import (
"encoding/json"
"fmt"
log "github.com/sirupsen/logrus"
"io/ioutil"
"os"
"strings"
log "github.com/sirupsen/logrus"

"github.com/go-playground/locales/en"
ut "github.com/go-playground/universal-translator"
Expand Down
5 changes: 5 additions & 0 deletions pkg/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Stats interface {
Mean() (float64, error)
Median() (float64, error)
Percentile(percent float64) (float64, error)
StdDev() (float64, error)
ErrorRate() float64
}

Expand Down Expand Up @@ -63,6 +64,10 @@ func (ss *sstats) Mean() (float64, error) {
return stats.Mean(ss.float64Samples)
}

func (ss *sstats) StdDev() (float64, error) {
return stats.StandardDeviation(ss.float64Samples)
}

func (ss *sstats) Median() (float64, error) {
return stats.Median(ss.float64Samples)
}
Expand Down

0 comments on commit b31a385

Please sign in to comment.