Skip to content

Commit 85b5d11

Browse files
committed
crypto/subtle: add additional benchmarks for XORBytes
Provide alignment benchmarks for XORBytes, as well as including 8192 byte blocks in the existing benchmarks. This allows us to better evaluate performance with unaligned inputs. Change-Id: Iad497c594c0425389ae02ca848aede5cb0ac3afd Reviewed-on: https://go-review.googlesource.com/c/go/+/639316 Reviewed-by: Cherry Mui <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Filippo Valsorda <[email protected]> Reviewed-by: Roland Shoemaker <[email protected]>
1 parent 76c18e2 commit 85b5d11

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/crypto/subtle/xor_test.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func BenchmarkXORBytes(b *testing.B) {
9292
dst := make([]byte, 1<<15)
9393
data0 := make([]byte, 1<<15)
9494
data1 := make([]byte, 1<<15)
95-
sizes := []int64{1 << 3, 1 << 7, 1 << 11, 1 << 15}
95+
sizes := []int64{1 << 3, 1 << 7, 1 << 11, 1 << 13, 1 << 15}
9696
for _, size := range sizes {
9797
b.Run(fmt.Sprintf("%dBytes", size), func(b *testing.B) {
9898
s0 := data0[:size]
@@ -105,6 +105,26 @@ func BenchmarkXORBytes(b *testing.B) {
105105
}
106106
}
107107

108+
func BenchmarkXORBytesAlignment(b *testing.B) {
109+
dst := make([]byte, 8+1<<11)
110+
data0 := make([]byte, 8+1<<11)
111+
data1 := make([]byte, 8+1<<11)
112+
sizes := []int64{1 << 3, 1 << 7, 1 << 11}
113+
for _, size := range sizes {
114+
for offset := int64(0); offset < 8; offset++ {
115+
b.Run(fmt.Sprintf("%dBytes%dOffset", size, offset), func(b *testing.B) {
116+
d := dst[offset : offset+size]
117+
s0 := data0[offset : offset+size]
118+
s1 := data1[offset : offset+size]
119+
b.SetBytes(int64(size))
120+
for i := 0; i < b.N; i++ {
121+
XORBytes(d, s0, s1)
122+
}
123+
})
124+
}
125+
}
126+
}
127+
108128
func mustPanic(t *testing.T, expected string, f func()) {
109129
t.Helper()
110130
defer func() {

0 commit comments

Comments
 (0)