-
Notifications
You must be signed in to change notification settings - Fork 17.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
all: faster midpoint computation in binary search
On my machine (3.1 GHz Quad-Core Intel Core i7, macOS 10.15.7 10.15.7), go 1.15.6 benchstat: name old time/op new time/op delta SearchInts-8 20.3ns ± 1% 16.6ns ± 6% -18.37% (p=0.000 n=9+10) Change-Id: I346e5955fd6df6ce10254b22267dbc8d5a2b16c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/279439 Reviewed-by: Ben Shi <powerman1st@163.com> Reviewed-by: Robert Griesemer <gri@golang.org> Trust: Robert Griesemer <gri@golang.org>
- Loading branch information
1 parent
f113e9a
commit 7af821a
Showing
5 changed files
with
30 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2021 The Go Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package token | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func BenchmarkSearchInts(b *testing.B) { | ||
data := make([]int, 10000) | ||
for i := 0; i < 10000; i++ { | ||
data[i] = i | ||
} | ||
const x = 8 | ||
if r := searchInts(data, x); r != x { | ||
b.Errorf("got index = %d; want %d", r, x) | ||
} | ||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
searchInts(data, x) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters