1
0
mirror of https://github.com/golang/go synced 2024-11-05 16:56:16 -07:00
go/cmd/benchcmp/benchcmp_test.go
Dominik Honnef 0ff6678340 benchmark/parse, cmd/benchcmp: new package for parsing benchmarks
Move the parser for benchmark output from cmd/benchcmp into its own
package, benchmark/parse.

The majority of the change is just moving code around. Instead of
implementing the '-best' flag in ParseBenchSet, it is now implemented in
its own function 'selectBest' in cmd/benchcmp.

Bench.Ord (the ordinal position of a Bench within a BenchSet) has been
exported.

Change-Id: Id27032a220f9ff2596117b58b86243998695a804
Reviewed-on: https://go-review.googlesource.com/2102
Reviewed-by: Rob Pike <r@golang.org>
2015-01-06 01:34:08 +00:00

60 lines
1023 B
Go

package main
import (
"reflect"
"testing"
"golang.org/x/tools/benchmark/parse"
)
func TestSelectBest(t *testing.T) {
have := parse.BenchSet{
"Benchmark1": []*parse.Bench{
{
Name: "Benchmark1",
N: 10, NsOp: 100, Measured: parse.NsOp,
Ord: 0,
},
{
Name: "Benchmark1",
N: 10, NsOp: 50, Measured: parse.NsOp,
Ord: 3,
},
},
"Benchmark2": []*parse.Bench{
{
Name: "Benchmark2",
N: 10, NsOp: 60, Measured: parse.NsOp,
Ord: 1,
},
{
Name: "Benchmark2",
N: 10, NsOp: 500, Measured: parse.NsOp,
Ord: 2,
},
},
}
want := parse.BenchSet{
"Benchmark1": []*parse.Bench{
{
Name: "Benchmark1",
N: 10, NsOp: 50, Measured: parse.NsOp,
Ord: 0,
},
},
"Benchmark2": []*parse.Bench{
{
Name: "Benchmark2",
N: 10, NsOp: 60, Measured: parse.NsOp,
Ord: 1,
},
},
}
selectBest(have)
if !reflect.DeepEqual(want, have) {
t.Errorf("filtered bench set incorrectly, want %v have %v", want, have)
}
}