diff --git a/internal/reporter.go b/internal/reporter.go index 623e1db..a00412c 100644 --- a/internal/reporter.go +++ b/internal/reporter.go @@ -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() @@ -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) diff --git a/internal/spec.go b/internal/spec.go index e576dbe..0b0799e 100644 --- a/internal/spec.go +++ b/internal/spec.go @@ -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" diff --git a/pkg/summary.go b/pkg/summary.go index 7542dd5..a0f92b7 100644 --- a/pkg/summary.go +++ b/pkg/summary.go @@ -11,6 +11,7 @@ type Stats interface { Mean() (float64, error) Median() (float64, error) Percentile(percent float64) (float64, error) + StdDev() (float64, error) ErrorRate() float64 } @@ -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) }