Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pkg/decoders/base64_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func BenchmarkFromChunkSmall(b *testing.B) {
d := Base64{}
data := detectors.MustGetBenchmarkData()["small"]

for n := 0; n < b.N; n++ {
for b.Loop() {
d.FromChunk(&sources.Chunk{Data: data})
}
}
Expand All @@ -164,7 +164,7 @@ func BenchmarkFromChunkMedium(b *testing.B) {
d := Base64{}
data := detectors.MustGetBenchmarkData()["medium"]

for n := 0; n < b.N; n++ {
for b.Loop() {
d.FromChunk(&sources.Chunk{Data: data})
}
}
Expand All @@ -173,7 +173,7 @@ func BenchmarkFromChunkLarge(b *testing.B) {
d := Base64{}
data := detectors.MustGetBenchmarkData()["big"]

for n := 0; n < b.N; n++ {
for b.Loop() {
d.FromChunk(&sources.Chunk{Data: data})
}
}
46 changes: 18 additions & 28 deletions pkg/decoders/escaped_unicode_bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,49 @@ var (

// Benchmark individual decoder functions
func BenchmarkDecodeOriginalEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeEscaped(originalUnicodeData)
}
}

func BenchmarkDecodeCodePoint(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeCodePoint(codePointData)
}
}

func BenchmarkDecodeBraceEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeBraceEscape(braceEscapeData)
}
}

func BenchmarkDecodeLongEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeLongEscape(longEscapeData)
}
}

func BenchmarkDecodePerlEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodePerlEscape(perlEscapeData)
}
}

func BenchmarkDecodeCssEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeCssEscape(cssEscapeData)
}
}

func BenchmarkDecodeHtmlEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodeHtmlEscape(htmlEscapeData)
}
}

func BenchmarkDecodePercentEscape(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decodePercentEscape(percentEscapeData)
}
}
Expand All @@ -118,8 +118,7 @@ func BenchmarkFromChunk_OriginalFormat(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: originalUnicodeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -128,8 +127,7 @@ func BenchmarkFromChunk_BraceFormat(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: braceEscapeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -138,8 +136,7 @@ func BenchmarkFromChunk_LongFormat(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: longEscapeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -148,8 +145,7 @@ func BenchmarkFromChunk_HtmlFormat(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: htmlEscapeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -158,8 +154,7 @@ func BenchmarkFromChunk_MixedContent(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: mixedContentData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -168,8 +163,7 @@ func BenchmarkFromChunk_NoUnicode(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: noUnicodeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -178,8 +172,7 @@ func BenchmarkFromChunk_LargeData(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: largeData}

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
_ = decoder.FromChunk(chunk)
}
}
Expand All @@ -188,8 +181,7 @@ func BenchmarkFromChunk_LargeData(b *testing.B) {
func BenchmarkRegexMatching_AllPatterns(b *testing.B) {
testData := mixedContentData

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
// Simulate the pattern matching in FromChunk
_ = longEscapePat.Match(testData)
_ = braceEscapePat.Match(testData)
Expand All @@ -206,8 +198,7 @@ func BenchmarkRegexMatching_AllPatterns(b *testing.B) {
func BenchmarkRegexMatching_NoMatch(b *testing.B) {
testData := noUnicodeData

b.ResetTimer()
for i := 0; i < b.N; i++ {
for b.Loop() {
// Simulate the pattern matching in FromChunk on data with no matches
_ = longEscapePat.Match(testData)
_ = braceEscapePat.Match(testData)
Expand All @@ -226,9 +217,8 @@ func BenchmarkFromChunk_MemoryAllocation(b *testing.B) {
decoder := &EscapedUnicode{}
chunk := &sources.Chunk{Data: mixedContentData}

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
for b.Loop() {
result := decoder.FromChunk(chunk)
if result != nil {
// Prevent compiler optimization
Expand Down
2 changes: 1 addition & 1 deletion pkg/decoders/utf16_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func BenchmarkUtf16ToUtf8(b *testing.B) {
// Example UTF-16LE encoded data
data := []byte{72, 0, 101, 0, 108, 0, 108, 0, 111, 0, 32, 0, 87, 0, 111, 0, 114, 0, 108, 0, 100, 0}

for n := 0; n < b.N; n++ {
for b.Loop() {
_, _ = utf16ToUTF8(data)
}
}
2 changes: 1 addition & 1 deletion pkg/decoders/utf8_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ go
away.`)

func Benchmark_extractSubstrings(b *testing.B) {
for i := 0; i < b.N; i++ {
for b.Loop() {
extractSubstrings(testBytes)
}
}