]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/subtle: add additional benchmarks for XORBytes
authorJoel Sing <joel@sing.id.au>
Fri, 3 Jan 2025 08:06:07 +0000 (19:06 +1100)
committerJoel Sing <joel@sing.id.au>
Fri, 7 Feb 2025 09:32:39 +0000 (01:32 -0800)
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 <cherryyz@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Filippo Valsorda <filippo@golang.org>
Reviewed-by: Roland Shoemaker <roland@golang.org>
src/crypto/subtle/xor_test.go

index 2e2169db0aac627eff8cb176e9e7750ee41aa64f..855e54d82bb26f68159fe0e2be7282da8fa985e1 100644 (file)
@@ -92,7 +92,7 @@ func BenchmarkXORBytes(b *testing.B) {
        dst := make([]byte, 1<<15)
        data0 := make([]byte, 1<<15)
        data1 := make([]byte, 1<<15)
-       sizes := []int64{1 << 3, 1 << 7, 1 << 11, 1 << 15}
+       sizes := []int64{1 << 3, 1 << 7, 1 << 11, 1 << 13, 1 << 15}
        for _, size := range sizes {
                b.Run(fmt.Sprintf("%dBytes", size), func(b *testing.B) {
                        s0 := data0[:size]
@@ -105,6 +105,26 @@ func BenchmarkXORBytes(b *testing.B) {
        }
 }
 
+func BenchmarkXORBytesAlignment(b *testing.B) {
+       dst := make([]byte, 8+1<<11)
+       data0 := make([]byte, 8+1<<11)
+       data1 := make([]byte, 8+1<<11)
+       sizes := []int64{1 << 3, 1 << 7, 1 << 11}
+       for _, size := range sizes {
+               for offset := int64(0); offset < 8; offset++ {
+                       b.Run(fmt.Sprintf("%dBytes%dOffset", size, offset), func(b *testing.B) {
+                               d := dst[offset : offset+size]
+                               s0 := data0[offset : offset+size]
+                               s1 := data1[offset : offset+size]
+                               b.SetBytes(int64(size))
+                               for i := 0; i < b.N; i++ {
+                                       XORBytes(d, s0, s1)
+                               }
+                       })
+               }
+       }
+}
+
 func mustPanic(t *testing.T, expected string, f func()) {
        t.Helper()
        defer func() {