diff options
| author | Robert Griesemer <gri@golang.org> | 2017-02-17 15:02:49 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2017-02-17 23:40:45 +0000 |
| commit | 19028bdd18483689a3743639fa89d272cbb96c7b (patch) | |
| tree | 57878271b3cef4b4e0f24206ab3575f1c429dd39 /src/math/bits/bits_test.go | |
| parent | a12edb8db6f3fa93a1ccd96a0f84b647d08429ef (diff) | |
| download | go-19028bdd18483689a3743639fa89d272cbb96c7b.tar.xz | |
math/bits: faster Rotate functions, added respective benchmarks
Measured on 2.3 GHz Intel Core i7, running maxOS 10.12.3.
benchmark old ns/op new ns/op delta
BenchmarkRotateLeft-8 7.87 7.00 -11.05%
BenchmarkRotateLeft8-8 8.41 4.52 -46.25%
BenchmarkRotateLeft16-8 8.07 4.55 -43.62%
BenchmarkRotateLeft32-8 8.36 4.73 -43.42%
BenchmarkRotateLeft64-8 7.93 4.78 -39.72%
BenchmarkRotateRight-8 8.23 6.72 -18.35%
BenchmarkRotateRight8-8 8.76 4.39 -49.89%
BenchmarkRotateRight16-8 9.07 4.44 -51.05%
BenchmarkRotateRight32-8 8.85 4.46 -49.60%
BenchmarkRotateRight64-8 8.11 4.43 -45.38%
Change-Id: I79ea1e9e6fc65f95794a91f860a911efed3aa8a1
Reviewed-on: https://go-review.googlesource.com/37219
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/math/bits/bits_test.go')
| -rw-r--r-- | src/math/bits/bits_test.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/math/bits/bits_test.go b/src/math/bits/bits_test.go index b268b0a004..20b0b63fff 100644 --- a/src/math/bits/bits_test.go +++ b/src/math/bits/bits_test.go @@ -289,6 +289,46 @@ func TestRotateLeft(t *testing.T) { } } +func BenchmarkRotateLeft(b *testing.B) { + var s uint + for i := 0; i < b.N; i++ { + s += RotateLeft(uint(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateLeft8(b *testing.B) { + var s uint8 + for i := 0; i < b.N; i++ { + s += RotateLeft8(uint8(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateLeft16(b *testing.B) { + var s uint16 + for i := 0; i < b.N; i++ { + s += RotateLeft16(uint16(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateLeft32(b *testing.B) { + var s uint32 + for i := 0; i < b.N; i++ { + s += RotateLeft32(uint32(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateLeft64(b *testing.B) { + var s uint64 + for i := 0; i < b.N; i++ { + s += RotateLeft64(uint64(Input), i) + } + Unused = int(s) +} + func TestRotateRight(t *testing.T) { var m uint64 = deBruijn64 @@ -339,6 +379,46 @@ func TestRotateRight(t *testing.T) { } } +func BenchmarkRotateRight(b *testing.B) { + var s uint + for i := 0; i < b.N; i++ { + s += RotateRight(uint(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateRight8(b *testing.B) { + var s uint8 + for i := 0; i < b.N; i++ { + s += RotateRight8(uint8(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateRight16(b *testing.B) { + var s uint16 + for i := 0; i < b.N; i++ { + s += RotateRight16(uint16(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateRight32(b *testing.B) { + var s uint32 + for i := 0; i < b.N; i++ { + s += RotateRight32(uint32(Input), i) + } + Unused = int(s) +} + +func BenchmarkRotateRight64(b *testing.B) { + var s uint64 + for i := 0; i < b.N; i++ { + s += RotateRight64(uint64(Input), i) + } + Unused = int(s) +} + func TestReverse(t *testing.T) { // test each bit for i := uint(0); i < 64; i++ { |
