aboutsummaryrefslogtreecommitdiff
path: root/cmd/benchcmp/benchcmp_test.go
blob: f57e58c1247bd6aa1d4d641dd3f312048a53794b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
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)
	}
}