diff options
author | Martin Möhrmann <moehrmann@google.com> | 2017-08-07 22:36:22 +0200 |
---|---|---|
committer | Martin Möhrmann <moehrmann@google.com> | 2017-08-22 17:59:02 +0000 |
commit | 3216e0cefab43670c788a475237f6f4b235fc200 (patch) | |
tree | 5294f61c64a869cfe74442efcd91178c09ac3aa0 /src/runtime/runtime_test.go | |
parent | d05a1238d6811aa11abf117e668cd9c4f4c15e6a (diff) | |
download | go-3216e0cefab43670c788a475237f6f4b235fc200.tar.gz go-3216e0cefab43670c788a475237f6f4b235fc200.zip |
cmd/compile: replace eqstring with memequal
eqstring is only called for strings with equal lengths.
Instead of pushing a pointer and length for each argument string
on the stack we can omit pushing one of the lengths on the stack.
Changing eqstrings signature to eqstring(*uint8, *uint8, int) bool
to implement the above optimization would make it very similar to the
existing memequal(*any, *any, uintptr) bool function.
Since string lengths are positive we can avoid code redundancy and
use memequal instead of using eqstring with an optimized signature.
go command binary size reduced by 4128 bytes on amd64.
name old time/op new time/op delta
CompareStringEqual 6.03ns ± 1% 5.71ns ± 1% -5.23% (p=0.000 n=19+18)
CompareStringIdentical 2.88ns ± 1% 3.22ns ± 7% +11.86% (p=0.000 n=20+20)
CompareStringSameLength 4.31ns ± 1% 4.01ns ± 1% -7.17% (p=0.000 n=19+19)
CompareStringDifferentLength 0.29ns ± 2% 0.29ns ± 2% ~ (p=1.000 n=20+20)
CompareStringBigUnaligned 64.3µs ± 2% 64.1µs ± 3% ~ (p=0.164 n=20+19)
CompareStringBig 61.9µs ± 1% 61.6µs ± 2% -0.46% (p=0.033 n=20+19)
Change-Id: Ice15f3b937c981f0d3bc8479a9ea0d10658ac8df
Reviewed-on: https://go-review.googlesource.com/53650
Run-TryBot: Martin Möhrmann <moehrmann@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Diffstat (limited to 'src/runtime/runtime_test.go')
-rw-r--r-- | src/runtime/runtime_test.go | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/runtime/runtime_test.go b/src/runtime/runtime_test.go index e9bc256712..922cd830bc 100644 --- a/src/runtime/runtime_test.go +++ b/src/runtime/runtime_test.go @@ -196,9 +196,9 @@ func eqstring_generic(s1, s2 string) bool { } func TestEqString(t *testing.T) { - // This isn't really an exhaustive test of eqstring, it's + // This isn't really an exhaustive test of == on strings, it's // just a convenient way of documenting (via eqstring_generic) - // what eqstring does. + // what == does. s := []string{ "", "a", @@ -213,7 +213,7 @@ func TestEqString(t *testing.T) { x := s1 == s2 y := eqstring_generic(s1, s2) if x != y { - t.Errorf(`eqstring("%s","%s") = %t, want %t`, s1, s2, x, y) + t.Errorf(`("%s" == "%s") = %t, want %t`, s1, s2, x, y) } } } |