mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
bytes: SSE for bytes.IndexByte on amd64
Performance on 2.8 GHz Intel Core i7: Before: BenchmarkIndexByte4K 1000000 2997 ns/op 1366.70 MB/s BenchmarkIndexByte4M 500 3049772 ns/op 1375.28 MB/s BenchmarkIndexByte64M 50 49582280 ns/op 1353.48 MB/s After: BenchmarkIndexByte4K 10000000 298 ns/op 13744.97 MB/s BenchmarkIndexByte4M 10000 285993 ns/op 14665.76 MB/s BenchmarkIndexByte64M 500 4618172 ns/op 14531.48 MB/s R=rsc, PeterGo, r2, r CC=golang-dev https://golang.org/cl/2888041
This commit is contained in:
parent
e9c901dbf4
commit
49fdfe21dd
2 changed files with 137 additions and 9 deletions
|
|
@ -93,6 +93,9 @@ var indexTests = []BinOpTest{
|
|||
{"abc", "b", 1},
|
||||
{"abc", "c", 2},
|
||||
{"abc", "x", -1},
|
||||
{"barfoobarfooyyyzzzyyyzzzyyyzzzyyyxxxzzzyyy", "x", 33},
|
||||
{"foofyfoobarfoobar", "y", 4},
|
||||
{"oooooooooooooooooooooo", "r", -1},
|
||||
}
|
||||
|
||||
var lastIndexTests = []BinOpTest{
|
||||
|
|
@ -177,6 +180,56 @@ func TestIndexByte(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// test a larger buffer with different sizes and alignments
|
||||
func TestIndexByteBig(t *testing.T) {
|
||||
const n = 1024
|
||||
b := make([]byte, n)
|
||||
for i := 0; i < n; i++ {
|
||||
// different start alignments
|
||||
b1 := b[i:]
|
||||
for j := 0; j < len(b1); j++ {
|
||||
b1[j] = 'x'
|
||||
pos := IndexByte(b1, 'x')
|
||||
if pos != j {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
b1[j] = 0
|
||||
pos = IndexByte(b1, 'x')
|
||||
if pos != -1 {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
}
|
||||
// different end alignments
|
||||
b1 = b[:i]
|
||||
for j := 0; j < len(b1); j++ {
|
||||
b1[j] = 'x'
|
||||
pos := IndexByte(b1, 'x')
|
||||
if pos != j {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
b1[j] = 0
|
||||
pos = IndexByte(b1, 'x')
|
||||
if pos != -1 {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
}
|
||||
// different start and end alignments
|
||||
b1 = b[i/2 : n-(i+1)/2]
|
||||
for j := 0; j < len(b1); j++ {
|
||||
b1[j] = 'x'
|
||||
pos := IndexByte(b1, 'x')
|
||||
if pos != j {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
b1[j] = 0
|
||||
pos = IndexByte(b1, 'x')
|
||||
if pos != -1 {
|
||||
t.Errorf("IndexByte(%q, 'x') = %v", b1, pos)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestIndexRune(t *testing.T) {
|
||||
for _, tt := range indexRuneTests {
|
||||
a := []byte(tt.a)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue