Repository navigation
Expand file tree
/
Copy pathbench_test.go
More file actions
132 lines (105 loc) · 3.74 KB
/
Copy pathbench_test.go
File metadata and controls
132 lines (105 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
// SPDX-License-Identifier: Apache-2.0 OR MIT
//go:build goexperiment.simd && amd64
package c2simd_test
import (
"crypto/rand"
"runtime/debug"
"testing"
"code.hazyhaar.fr/devhoros/c2simd"
"code.hazyhaar.fr/devhoros/c2simd/internal/monocypher"
"golang.org/x/crypto/chacha20poly1305"
)
func generateBenchData(size int) ([]byte, []byte, []byte, []byte) {
key := make([]byte, 32)
nonce := make([]byte, 24)
ad := []byte("header_metadata_ad")
payload := make([]byte, size)
rand.Read(key)
rand.Read(nonce)
rand.Read(payload)
return key, nonce, ad, payload
}
// -----------------------------------------------------------------------------
// 1. Benchmark Monocypher Transpiled Baseline (ccgo) - Lock Only
// -----------------------------------------------------------------------------
func BenchmarkMonocypher_Lock_1MB(b *testing.B) {
key, nonce, ad, payload := generateBenchData(1024 * 1024)
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := monocypher.AEADLock(key, nonce, ad, payload)
if err != nil {
b.Fatal(err)
}
}
}
// -----------------------------------------------------------------------------
// 2. Benchmark Moteur c2simd Transformé (bits.RotateLeft32) - Lock Only
// -----------------------------------------------------------------------------
func BenchmarkC2SIMD_Lock_1MB(b *testing.B) {
key, nonce, ad, payload := generateBenchData(1024 * 1024)
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _, err := c2simd.AEADLock(key, nonce, ad, payload)
if err != nil {
b.Fatal(err)
}
}
}
// -----------------------------------------------------------------------------
// 3. Benchmark Fused SIMD256 Engine (0 libc.TLS - Fused AEAD) - Lock Only
// -----------------------------------------------------------------------------
func BenchmarkC2SIMD_FusedSIMD256_Lock_1MB(b *testing.B) {
key, nonce, ad, payload := generateBenchData(1024 * 1024)
dstBuffer := make([]byte, len(payload))
var mac [16]byte
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := c2simd.AEADLockSIMD256_FusedDst(dstBuffer, &mac, key, nonce, ad, payload)
if err != nil {
b.Fatal(err)
}
}
}
func BenchmarkC2SIMD_FusedSIMD256_Lock_1MB_ZeroAlloc_NoGC(b *testing.B) {
key, nonce, ad, payload := generateBenchData(1024 * 1024)
dstBuffer := make([]byte, len(payload))
var mac [16]byte
// Contrôle explicite du GC pour éliminer tout balayage résiduel
oldGC := debug.SetGCPercent(-1)
defer debug.SetGCPercent(oldGC)
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
c2simd.AEADLockSIMD256_FusedDst(dstBuffer, &mac, key, nonce, ad, payload)
}
}
// -----------------------------------------------------------------------------
// 4. Benchmark Chiffrement SIMD256 Pur AVX2 (archsimd.Uint32x8 - ChaCha20 Seul)
// -----------------------------------------------------------------------------
func BenchmarkC2SIMD_SIMD256_PureStream_1MB(b *testing.B) {
key, nonce, _, payload := generateBenchData(1024 * 1024)
dst := make([]byte, len(payload))
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
c2simd.EncryptChaCha20_SIMD256(key, nonce[:12], 1, payload, dst)
}
}
// -----------------------------------------------------------------------------
// 5. Benchmark Native Go SIMD (golang.org/x/crypto/chacha20poly1305) - Seal Only
// -----------------------------------------------------------------------------
func BenchmarkNativeGo_Seal_1MB(b *testing.B) {
key, nonce, ad, payload := generateBenchData(1024 * 1024)
aead, err := chacha20poly1305.NewX(key)
if err != nil {
b.Fatal(err)
}
b.SetBytes(int64(len(payload)))
b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = aead.Seal(nil, nonce, payload, ad)
}
}