-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathencode_bench_test.go
More file actions
118 lines (99 loc) · 2.56 KB
/
Copy pathencode_bench_test.go
File metadata and controls
118 lines (99 loc) · 2.56 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
// SPDX-License-Identifier: EUPL-1.2
// Benchmarks for the encoding primitives in encode.go.
// Per AX-11 — hex + base64 are on every fingerprint emit, every API
// auth-header build, every model-hash compare, every keys.Pack write.
// The wrappers are encoding/{hex,base64} passthroughs; the bench
// harness gates the contract so a Core reroute can't slow them silently.
//
// Run: go test -bench='BenchmarkEncode' -benchmem -run='^$' .
package core_test
import (
. "dappco.re/go"
)
// Sinks defeat compiler DCE.
var (
encodeSinkString string
encodeSinkResult Result
)
// --- Fixtures ---
//
// 16-byte payload mirrors SHA-256 truncated or a small auth token.
// 1KB payload covers larger blobs (model header chunk, jwt body).
var (
encodeBytes16 = []byte("aaaaaaaaaaaaaaaa")
encodeBytes1K = func() []byte {
out := make([]byte, 1024)
for i := range out {
out[i] = byte('a' + i%26)
}
return out
}()
)
// --- Hex ---
func BenchmarkEncode_HexEncode_16B(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkString = HexEncode(encodeBytes16)
}
}
func BenchmarkEncode_HexEncode_1KB(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkString = HexEncode(encodeBytes1K)
}
}
func BenchmarkEncode_HexDecode_16B(b *B) {
encoded := HexEncode(encodeBytes16)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkResult = HexDecode(encoded)
}
}
func BenchmarkEncode_HexDecode_1KB(b *B) {
encoded := HexEncode(encodeBytes1K)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkResult = HexDecode(encoded)
}
}
// --- Base64 std ---
func BenchmarkEncode_Base64Encode_16B(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkString = Base64Encode(encodeBytes16)
}
}
func BenchmarkEncode_Base64Encode_1KB(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkString = Base64Encode(encodeBytes1K)
}
}
func BenchmarkEncode_Base64Decode_16B(b *B) {
encoded := Base64Encode(encodeBytes16)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkResult = Base64Decode(encoded)
}
}
func BenchmarkEncode_Base64Decode_1KB(b *B) {
encoded := Base64Encode(encodeBytes1K)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkResult = Base64Decode(encoded)
}
}
// --- Base64 url ---
func BenchmarkEncode_Base64URLEncode_16B(b *B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkString = Base64URLEncode(encodeBytes16)
}
}
func BenchmarkEncode_Base64URLDecode_16B(b *B) {
encoded := Base64URLEncode(encodeBytes16)
b.ReportAllocs()
for i := 0; i < b.N; i++ {
encodeSinkResult = Base64URLDecode(encoded)
}
}