diff --git a/stats/stats.go b/stats/stats.go index ee57c18..bb72593 100644 --- a/stats/stats.go +++ b/stats/stats.go @@ -59,6 +59,34 @@ type Stats struct { Generations int } +// the following three methods implement the sort.Interface. +func (a AlgoMean) Len() int { + return len(a.Means) +} + +func (a AlgoMean) Less(i, j int) bool { + return a.Means[i].Bench < a.Means[j].Bench +} + +func (a AlgoMean) Swap(i, j int) { + a.Means[i], a.Means[j] = a.Means[j], a.Means[i] +} + +// the following three methods also implement the sort.Interface. +func (m MeanStats) Len() int { + return len(m.AlgoMeans) +} + +// this in fact sorts in reverse (fits with our use case atm). +func (m MeanStats) Less(i, j int) bool { + // return m.AlgoMeans[i].Algo < m.AlgoMeans[j].Algo + return m.AlgoMeans[i].Algo > m.AlgoMeans[j].Algo +} + +func (m MeanStats) Swap(i, j int) { + m.AlgoMeans[i], m.AlgoMeans[j] = m.AlgoMeans[j], m.AlgoMeans[i] +} + func GetFuncStats(funcName string, benchResults []BenchRound) FuncStats { f := FuncStats{ BenchName: funcName,