aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/hash_test.go
diff options
context:
space:
mode:
authorKeith Randall <khr@golang.org>2016-03-17 13:28:04 -0700
committerKeith Randall <khr@golang.org>2016-03-18 19:21:53 +0000
commit15ea61146e49b91b84b7b3a3096b13ddfb4cc01f (patch)
tree83af07593ed225775ec16a4d3509a043525f8cb1 /src/runtime/hash_test.go
parent982322769c1ca0e038d21a7028359c363acb7b8e (diff)
downloadgo-15ea61146e49b91b84b7b3a3096b13ddfb4cc01f.tar.gz
go-15ea61146e49b91b84b7b3a3096b13ddfb4cc01f.zip
runtime: use unaligned loads on ppc64
benchmark old ns/op new ns/op delta BenchmarkAlignedLoad-160 8.67 7.42 -14.42% BenchmarkUnalignedLoad-160 8.63 7.37 -14.60% Change-Id: Id4609d7b4038c4d2ec332efc4fe6f1adfb61b82b Reviewed-on: https://go-review.googlesource.com/20812 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/runtime/hash_test.go')
-rw-r--r--src/runtime/hash_test.go22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/runtime/hash_test.go b/src/runtime/hash_test.go
index 7cceab86cc..0022fd39a5 100644
--- a/src/runtime/hash_test.go
+++ b/src/runtime/hash_test.go
@@ -11,6 +11,7 @@ import (
. "runtime"
"strings"
"testing"
+ "unsafe"
)
// Smhasher is a torture test for hash functions.
@@ -658,3 +659,24 @@ func TestStructHash(t *testing.T) {
t.Errorf("too many allocs %f - hash not balanced", n)
}
}
+
+var sink uint64
+
+func BenchmarkAlignedLoad(b *testing.B) {
+ var buf [16]byte
+ p := unsafe.Pointer(&buf[0])
+ var s uint64
+ for i := 0; i < b.N; i++ {
+ s += ReadUnaligned64(p)
+ }
+ sink = s
+}
+func BenchmarkUnalignedLoad(b *testing.B) {
+ var buf [16]byte
+ p := unsafe.Pointer(&buf[1])
+ var s uint64
+ for i := 0; i < b.N; i++ {
+ s += ReadUnaligned64(p)
+ }
+ sink = s
+}