From bd70bd9cb2f458b23222083a3a11190f080af7fd Mon Sep 17 00:00:00 2001 From: Keith Randall Date: Mon, 22 Feb 2016 13:20:38 -0800 Subject: runtime: unify memeq and memequal They do the same thing, except memequal also has the short-circuit check if the two pointers are equal. A) We might as well always do the short-circuit check, it is only 2 instructions. B) The extra function call (memequal->memeq) is expensive. benchmark old ns/op new ns/op delta BenchmarkArrayEqual-8 8.56 5.31 -37.97% No noticeable affect on the former memeq user (maps). Fixes #14302 Change-Id: I85d1ada59ed11e64dd6c54667f79d32cc5f81948 Reviewed-on: https://go-review.googlesource.com/19843 Run-TryBot: Keith Randall TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/runtime/string_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/runtime/string_test.go') diff --git a/src/runtime/string_test.go b/src/runtime/string_test.go index 150a25520a..37b75c1a89 100644 --- a/src/runtime/string_test.go +++ b/src/runtime/string_test.go @@ -102,6 +102,17 @@ func BenchmarkRuneIterate2(b *testing.B) { } } +func BenchmarkArrayEqual(b *testing.B) { + a1 := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + a2 := [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16} + b.ResetTimer() + for i := 0; i < b.N; i++ { + if a1 != a2 { + b.Fatal("not equal") + } + } +} + func TestStringW(t *testing.T) { strings := []string{ "hello", -- cgit v1.3