runtime: implement eqstring in assembly.

BenchmarkCompareStringEqual               10.4          7.33          -29.52%
BenchmarkCompareStringIdentical           3.99          3.67          -8.02%
BenchmarkCompareStringSameLength          9.80          6.84          -30.20%
BenchmarkCompareStringDifferentLength     1.09          0.95          -12.84%
BenchmarkCompareStringBigUnaligned        75220         76071         +1.13%
BenchmarkCompareStringBig                 69843         74746         +7.02%

LGTM=bradfitz, josharian
R=golang-codereviews, bradfitz, josharian, dave, khr
CC=golang-codereviews
https://golang.org/cl/105280044
This commit is contained in:
Keith Randall 2014-06-16 21:00:37 -07:00
parent 38eea5b2ad
commit b36ed9056f
6 changed files with 131 additions and 12 deletions

View file

@ -202,3 +202,41 @@ func testSetPanicOnFault(t *testing.T, addr uintptr) {
println(*p)
t.Fatalf("still here - should have faulted on address %#x", addr)
}
func eqstring_generic(s1, s2 string) bool {
if len(s1) != len(s2) {
return false
}
// optimization in assembly versions:
// if s1.str == s2.str { return true }
for i := 0; i < len(s1); i++ {
if s1[i] != s2[i] {
return false
}
}
return true
}
func TestEqString(t *testing.T) {
// This isn't really an exhaustive test of eqstring, it's
// just a convenient way of documenting (via eqstring_generic)
// what eqstring does.
s := []string{
"",
"a",
"c",
"aaa",
"ccc",
"cccc"[:3], // same contents, different string
"1234567890",
}
for _, s1 := range s {
for _, s2 := range s {
x := s1 == s2
y := eqstring_generic(s1, s2)
if x != y {
t.Errorf(`eqstring("%s","%s") = %t, want %t`, s1, s2, x, y)
}
}
}
}