Skip to content

Commit 47d3a6d

Browse files
authored
Merge pull request #858 from google/test-benchmark
refactor: Rename benchmark function for readability.
2 parents 28136c2 + 4db5001 commit 47d3a6d

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

.github/workflows/benchmark.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,5 @@ jobs:
3333
external-data-json-path: ./cache/benchmark-data.json
3434
save-data-file: ${{ github.event_name != 'pull_request' }}
3535
github-token: ${{ secrets.GITHUB_TOKEN }}
36-
comment-always: true
36+
comment-on-alert: true
3737
summary-always: true

internal/metrics/store_bench_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ func newRandMetric(tb testing.TB, rand *rand.Rand, i int) *Metric {
4848
}
4949

5050
type bench struct {
51-
name string
52-
setup func(b *testing.B, rand *rand.Rand, items int, m *[]*Metric, s *Store)
53-
b func(b *testing.B, items int, m []*Metric, s *Store)
51+
name string
52+
setup func(b *testing.B, rand *rand.Rand, items int, m *[]*Metric, s *Store)
53+
benchFunc func(b *testing.B, items int, m []*Metric, s *Store)
5454
}
5555

5656
func fillMetric(b *testing.B, rand *rand.Rand, items int, m *[]*Metric, _ *Store) {
@@ -70,9 +70,9 @@ func addToStore(b *testing.B, items int, m []*Metric, s *Store) {
7070
func BenchmarkStore(b *testing.B) {
7171
benches := []bench{
7272
{
73-
name: "Add",
74-
setup: fillMetric,
75-
b: addToStore,
73+
name: "Add",
74+
setup: fillMetric,
75+
benchFunc: addToStore,
7676
},
7777
{
7878
name: "Iterate",
@@ -81,7 +81,7 @@ func BenchmarkStore(b *testing.B) {
8181
fillMetric(b, rand, items, m, s)
8282
addToStore(b, items, *m, s)
8383
},
84-
b: func(b *testing.B, _ int, _ []*Metric, s *Store) {
84+
benchFunc: func(b *testing.B, _ int, _ []*Metric, s *Store) {
8585
b.Helper()
8686
s.Range(func(*Metric) error {
8787
return nil
@@ -117,12 +117,12 @@ func BenchmarkStore(b *testing.B) {
117117
if parallel {
118118
b.RunParallel(func(pb *testing.PB) {
119119
for pb.Next() {
120-
bench.b(b, items, m, s)
120+
bench.benchFunc(b, items, m, s)
121121
}
122122
})
123123
} else {
124124
for n := 0; n < b.N; n++ {
125-
bench.b(b, items, m, s)
125+
bench.benchFunc(b, items, m, s)
126126
if gc {
127127
s.Gc()
128128
}

0 commit comments

Comments
 (0)