mirror of
https://github.com/golang/go
synced 2024-10-02 08:28:36 -06:00
ee349b5d77
Add arm64 assembly implementation of runtime.cmpstring and bytes.Compare. benchmark old ns/op new ns/op delta BenchmarkCompareBytesEqual 98.0 27.5 -71.94% BenchmarkCompareBytesToNil 9.38 10.0 +6.61% BenchmarkCompareBytesEmpty 13.3 10.0 -24.81% BenchmarkCompareBytesIdentical 98.0 27.5 -71.94% BenchmarkCompareBytesSameLength 43.3 16.3 -62.36% BenchmarkCompareBytesDifferentLength 43.4 16.3 -62.44% BenchmarkCompareBytesBigUnaligned 6979680 1360979 -80.50% BenchmarkCompareBytesBig 6915995 1381979 -80.02% BenchmarkCompareBytesBigIdentical 6781440 1327304 -80.43% benchmark old MB/s new MB/s speedup BenchmarkCompareBytesBigUnaligned 150.23 770.46 5.13x BenchmarkCompareBytesBig 151.62 758.76 5.00x BenchmarkCompareBytesBigIdentical 154.63 790.01 5.11x * note, the machine we are benchmarking on has some issues. What is clear is compared to a few days ago the old MB/s value has increased from ~115 to 150. I'm less certain about the new MB/s number, which used to be close to 1Gb/s. Change-Id: I4f31b2c7a06296e13912aacc958525632cb0450d Reviewed-on: https://go-review.googlesource.com/8541 Reviewed-by: Aram Hăvărneanu <aram@mgk.ro> Reviewed-by: David Crawshaw <crawshaw@golang.org>
59 lines
950 B
Go
59 lines
950 B
Go
// Copyright 2013 The Go Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
// Routines that are implemented in assembly in asm_{amd64,386,arm,arm64}.s
|
|
|
|
// +build ppc64 ppc64le
|
|
|
|
package runtime
|
|
|
|
import _ "unsafe" // for go:linkname
|
|
|
|
func cmpstring(s1, s2 string) int {
|
|
l := len(s1)
|
|
if len(s2) < l {
|
|
l = len(s2)
|
|
}
|
|
for i := 0; i < l; i++ {
|
|
c1, c2 := s1[i], s2[i]
|
|
if c1 < c2 {
|
|
return -1
|
|
}
|
|
if c1 > c2 {
|
|
return +1
|
|
}
|
|
}
|
|
if len(s1) < len(s2) {
|
|
return -1
|
|
}
|
|
if len(s1) > len(s2) {
|
|
return +1
|
|
}
|
|
return 0
|
|
}
|
|
|
|
//go:linkname bytes_Compare bytes.Compare
|
|
func bytes_Compare(s1, s2 []byte) int {
|
|
l := len(s1)
|
|
if len(s2) < l {
|
|
l = len(s2)
|
|
}
|
|
for i := 0; i < l; i++ {
|
|
c1, c2 := s1[i], s2[i]
|
|
if c1 < c2 {
|
|
return -1
|
|
}
|
|
if c1 > c2 {
|
|
return +1
|
|
}
|
|
}
|
|
if len(s1) < len(s2) {
|
|
return -1
|
|
}
|
|
if len(s1) > len(s2) {
|
|
return +1
|
|
}
|
|
return 0
|
|
}
|