From 7b7b103c0f31195b93ffe401c068a059eb19eae1 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 14 Jun 2026 18:05:35 +0200 Subject: [PATCH 1/2] fix: remove unused generateRealisticRecords --- test_helpers_test.go | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/test_helpers_test.go b/test_helpers_test.go index a134015..8980bde 100644 --- a/test_helpers_test.go +++ b/test_helpers_test.go @@ -275,18 +275,3 @@ func generateEscapedQuotesRecords(numRows, numCols int) [][]string { } return records } - -// generateRealisticRecords returns records matching generateRealisticCSV. -func generateRealisticRecords(numRows, _ int) [][]string { - template := []string{ - "Alice, Smith", "30", "Tokyo, JP", "engineer", - "100", "Japan, Asia", "active", "42", "New York, US", "2024", - } - records := make([][]string, numRows) - for i := range records { - row := make([]string, len(template)) - copy(row, template) - records[i] = row - } - return records -} From f9f65f8bfb07781294d00f0f2e1e3f3fba334318 Mon Sep 17 00:00:00 2001 From: nnnkkk7 Date: Sun, 14 Jun 2026 18:14:39 +0200 Subject: [PATCH 2/2] bench: split Realistic into 20% and 40% quoted variants --- benchmark_test.go | 32 ++++++++++++++++++++++++++++---- test_helpers_test.go | 19 +++++++++++++++---- 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/benchmark_test.go b/benchmark_test.go index 8bb6b18..ac53f04 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -139,12 +139,36 @@ func BenchmarkReadAll_Quoted_100K_SIMD(b *testing.B) { } } +// ============================================================================= +// ReadAll Benchmarks - Realistic CSV (20% quoted) +// ============================================================================= + +func BenchmarkReadAll_Realistic20_100K_Stdlib(b *testing.B) { + data := generateRealistic20CSV(100000, 10) + b.SetBytes(int64(len(data))) + for b.Loop() { + reader := csv.NewReader(bytes.NewReader(data)) + reader.FieldsPerRecord = -1 + _, _ = reader.ReadAll() + } +} + +func BenchmarkReadAll_Realistic20_100K_SIMD(b *testing.B) { + data := generateRealistic20CSV(100000, 10) + b.SetBytes(int64(len(data))) + for b.Loop() { + reader := NewReader(bytes.NewReader(data)) + reader.FieldsPerRecord = -1 + _, _ = reader.ReadAll() + } +} + // ============================================================================= // ReadAll Benchmarks - Realistic CSV (40% quoted) // ============================================================================= -func BenchmarkReadAll_Realistic_100K_Stdlib(b *testing.B) { - data := generateRealisticCSV(100000, 10) +func BenchmarkReadAll_Realistic40_100K_Stdlib(b *testing.B) { + data := generateRealistic40CSV(100000, 10) b.SetBytes(int64(len(data))) for b.Loop() { reader := csv.NewReader(bytes.NewReader(data)) @@ -153,8 +177,8 @@ func BenchmarkReadAll_Realistic_100K_Stdlib(b *testing.B) { } } -func BenchmarkReadAll_Realistic_100K_SIMD(b *testing.B) { - data := generateRealisticCSV(100000, 10) +func BenchmarkReadAll_Realistic40_100K_SIMD(b *testing.B) { + data := generateRealistic40CSV(100000, 10) b.SetBytes(int64(len(data))) for b.Loop() { reader := NewReader(bytes.NewReader(data)) diff --git a/test_helpers_test.go b/test_helpers_test.go index 8980bde..10fbb3d 100644 --- a/test_helpers_test.go +++ b/test_helpers_test.go @@ -203,11 +203,22 @@ func generateEscapedQuotesCSV(numRows, numCols int) []byte { return buf.Bytes() } -// generateRealisticCSV generates CSV with 4/10 quoted fields containing commas (~40%). +// generateRealistic20CSV generates CSV with 2/10 quoted fields containing commas (~20%). +// Row template: "Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,"New York, US",2024 +// Cols 0,8 are quoted. +func generateRealistic20CSV(numRows, _ int) []byte { + var buf bytes.Buffer + for i := 0; i < numRows; i++ { + buf.WriteString(`"Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,"New York, US",2024`) + buf.WriteByte('\n') + } + return buf.Bytes() +} + +// generateRealistic40CSV generates CSV with 4/10 quoted fields containing commas (~40%). // Row template: "Alice, Smith",30,"Tokyo, JP",engineer,100,"Japan, Asia",active,42,"New York, US",2024 -// Cols 0,2,5,8 are quoted; this exercises the prefixXOR / PCLMULQDQ hot path -// without the all-quoted overhead. -func generateRealisticCSV(numRows, _ int) []byte { +// Cols 0,2,5,8 are quoted. +func generateRealistic40CSV(numRows, _ int) []byte { var buf bytes.Buffer for i := 0; i < numRows; i++ { buf.WriteString(`"Alice, Smith",30,"Tokyo, JP",engineer,100,"Japan, Asia",active,42,"New York, US",2024`)