slices,sort: explicitly discard results in benchmarks

The unusedresult analyzer will report failure to use the results
of these pure functions.

Updates #73950

Change-Id: I783cb92ad913105afd46c782bedf6234410c645d
Reviewed-on: https://go-review.googlesource.com/c/go/+/677995
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
Commit-Queue: Alan Donovan <adonovan@google.com>
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Alan Donovan 2025-06-02 11:27:08 -04:00
parent a8e99ab19c
commit e9d3b030ed
3 changed files with 7 additions and 7 deletions

View File

@ -23,7 +23,7 @@ func BenchmarkBinarySearchFloats(b *testing.B) {
needle := (floats[midpoint] + floats[midpoint+1]) / 2 needle := (floats[midpoint] + floats[midpoint+1]) / 2
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
slices.BinarySearch(floats, needle) _, _ = slices.BinarySearch(floats, needle)
} }
}) })
} }
@ -46,7 +46,7 @@ func BenchmarkBinarySearchFuncStruct(b *testing.B) {
cmpFunc := func(a, b *myStruct) int { return a.n - b.n } cmpFunc := func(a, b *myStruct) int { return a.n - b.n }
b.ResetTimer() b.ResetTimer()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
slices.BinarySearchFunc(structs, needle, cmpFunc) _, _ = slices.BinarySearchFunc(structs, needle, cmpFunc)
} }
}) })
} }

View File

@ -264,19 +264,19 @@ func TestMinMaxPanics(t *testing.T) {
intCmp := func(a, b int) int { return a - b } intCmp := func(a, b int) int { return a - b }
emptySlice := []int{} emptySlice := []int{}
if !panics(func() { Min(emptySlice) }) { if !panics(func() { _ = Min(emptySlice) }) {
t.Errorf("Min([]): got no panic, want panic") t.Errorf("Min([]): got no panic, want panic")
} }
if !panics(func() { Max(emptySlice) }) { if !panics(func() { _ = Max(emptySlice) }) {
t.Errorf("Max([]): got no panic, want panic") t.Errorf("Max([]): got no panic, want panic")
} }
if !panics(func() { MinFunc(emptySlice, intCmp) }) { if !panics(func() { _ = MinFunc(emptySlice, intCmp) }) {
t.Errorf("MinFunc([]): got no panic, want panic") t.Errorf("MinFunc([]): got no panic, want panic")
} }
if !panics(func() { MaxFunc(emptySlice, intCmp) }) { if !panics(func() { _ = MaxFunc(emptySlice, intCmp) }) {
t.Errorf("MaxFunc([]): got no panic, want panic") t.Errorf("MaxFunc([]): got no panic, want panic")
} }
} }

View File

@ -85,7 +85,7 @@ func BenchmarkSlicesIsSorted(b *testing.B) {
b.StopTimer() b.StopTimer()
ints := makeSortedInts(N) ints := makeSortedInts(N)
b.StartTimer() b.StartTimer()
slices.IsSorted(ints) _ = slices.IsSorted(ints)
} }
} }