-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbenchmark_test.go
More file actions
177 lines (158 loc) · 4.37 KB
/
benchmark_test.go
File metadata and controls
177 lines (158 loc) · 4.37 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package helper_test
import (
"bytes"
"strings"
"testing"
"github.com/Defacto2/helper"
)
// Benchmarks for performance-critical functions
// BenchmarkDeleteDupe - Deduplication (O(n²) before fix).
func BenchmarkDeleteDupe(b *testing.B) {
input := []string{
"group1", "group2", "group1", "group3", "group2",
"group4", "group5", "group3", "group1", "group6",
}
b.ResetTimer()
for b.Loop() {
helper.DeleteDupe(input...)
}
}
// BenchmarkDeleteDupeLarge - Deduplication with larger input.
func BenchmarkDeleteDupeLarge(b *testing.B) {
input := make([]string, 100)
for i := range 100 {
input[i] = "group" + string(rune(i%20))
}
b.ResetTimer()
for b.Loop() {
helper.DeleteDupe(input...)
}
}
// BenchmarkSlug - String slug generation (regex recompilation before fix).
func BenchmarkSlug(b *testing.B) {
tests := []string{
"The-Group",
"group1, group2",
"GROUP 👾",
"Mooñpeople",
"test_slug-name",
}
b.ResetTimer()
for b.Loop() {
for _, s := range tests {
helper.Slug(s)
}
}
}
// BenchmarkMask - String masking with patterns.
func BenchmarkMask(b *testing.B) {
input := []byte("1234-5678-ABCD-EFGH-IJKL-MNOP serial key test")
b.ResetTimer()
for b.Loop() {
helper.Mask(input...)
}
}
// BenchmarkObfuscateID - ID obfuscation.
func BenchmarkObfuscateID(b *testing.B) {
ids := []int64{1, 100, 1000, 10000, 999999}
b.ResetTimer()
for b.Loop() {
for _, id := range ids {
helper.ObfuscateID(id)
}
}
}
// BenchmarkObfuscate - String obfuscation.
func BenchmarkObfuscate(b *testing.B) {
inputs := []string{"1", "100", "1000", "12345", "999999"}
b.ResetTimer()
for b.Loop() {
for _, s := range inputs {
helper.Obfuscate(s)
}
}
}
// BenchmarkSplitAsSpaces - Space normalization.
func BenchmarkSplitAsSpaces(b *testing.B) {
input := "test\nwith\r\nmultiple\ttypes\rof\fwhitespace"
b.ResetTimer()
for b.Loop() {
helper.SplitAsSpaces(input)
}
}
// BenchmarkIntegrity - File comparison (uses fileMatch internally).
func BenchmarkIntegrity(b *testing.B) {
data1 := bytes.Repeat([]byte("x"), 10000)
data2 := bytes.Repeat([]byte("y"), 10000)
b.ResetTimer()
for b.Loop() {
helper.IntegrityBytes(data1)
_ = data2
}
}
// BenchmarkAdd1 - Numeric increment (uses reflection before fix).
func BenchmarkAdd1(b *testing.B) {
tests := []any{"test", int32(100), int64(1000), "another"}
b.ResetTimer()
for b.Loop() {
for _, val := range tests {
helper.Add1(val)
}
}
}
// BenchmarkDetermineUTF8 - UTF-8 text detection with emojis.
func BenchmarkDetermineUTF8(b *testing.B) {
utf8Text := "Hello 👾 😀 🎮 This is UTF-8 text with emojis!"
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(utf8Text))
}
}
// BenchmarkDetermineUTF8WithBOM - UTF-8 with BOM (fast path).
func BenchmarkDetermineUTF8WithBOM(b *testing.B) {
utf8WithBOM := "\xEF\xBB\xBFHello World - UTF-8 with BOM"
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(utf8WithBOM))
}
}
// BenchmarkDetermineCP437 - CP-437 text detection with ANSI art.
func BenchmarkDetermineCP437(b *testing.B) {
cp437Text := "┌─────────────────────────────┐\n│ CP-437 ANSI Art Example │\n└─────────────────────────────┘"
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(cp437Text))
}
}
// BenchmarkDetermineLatin1 - ISO-8859-1 text detection.
func BenchmarkDetermineLatin1(b *testing.B) {
latin1Text := "Café résumé naïve façade - Latin-1 text with accents"
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(latin1Text))
}
}
// BenchmarkDetermineASCII - Plain ASCII text (default case).
func BenchmarkDetermineASCII(b *testing.B) {
asciiText := "This is plain ASCII text without any special characters"
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(asciiText))
}
}
// BenchmarkDetermineLargeUTF8 - Large UTF-8 file (64KB).
func BenchmarkDetermineLargeUTF8(b *testing.B) {
largeUTF8 := strings.Repeat("Hello 👾 World! ", 1000)
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(largeUTF8))
}
}
// BenchmarkDetermineLargeCP437 - Large CP-437 file (64KB).
func BenchmarkDetermineLargeCP437(b *testing.B) {
largeCP437 := strings.Repeat("┌────┐\n│Test│\n└────┘", 100)
b.ResetTimer()
for b.Loop() {
helper.Determine(strings.NewReader(largeCP437))
}
}