diff --git a/benchmark_test.go b/benchmark_test.go index ac53f04..b196907 100644 --- a/benchmark_test.go +++ b/benchmark_test.go @@ -139,6 +139,30 @@ func BenchmarkReadAll_Quoted_100K_SIMD(b *testing.B) { } } +// ============================================================================= +// ReadAll Benchmarks - Realistic CSV (10% quoted) +// ============================================================================= + +func BenchmarkReadAll_Realistic10_100K_Stdlib(b *testing.B) { + data := generateRealistic10CSV(100000, 10) + b.SetBytes(int64(len(data))) + for b.Loop() { + reader := csv.NewReader(bytes.NewReader(data)) + reader.FieldsPerRecord = -1 + _, _ = reader.ReadAll() + } +} + +func BenchmarkReadAll_Realistic10_100K_SIMD(b *testing.B) { + data := generateRealistic10CSV(100000, 10) + b.SetBytes(int64(len(data))) + for b.Loop() { + reader := NewReader(bytes.NewReader(data)) + reader.FieldsPerRecord = -1 + _, _ = reader.ReadAll() + } +} + // ============================================================================= // ReadAll Benchmarks - Realistic CSV (20% quoted) // ============================================================================= diff --git a/test_helpers_test.go b/test_helpers_test.go index 10fbb3d..2b9eecc 100644 --- a/test_helpers_test.go +++ b/test_helpers_test.go @@ -203,6 +203,18 @@ func generateEscapedQuotesCSV(numRows, numCols int) []byte { return buf.Bytes() } +// generateRealistic10CSV generates CSV with 1/10 quoted fields containing commas (~10%). +// Row template: "Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,NewYork,2024 +// Col 0 is quoted. +func generateRealistic10CSV(numRows, _ int) []byte { + var buf bytes.Buffer + for i := 0; i < numRows; i++ { + buf.WriteString(`"Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,NewYork,2024`) + buf.WriteByte('\n') + } + return buf.Bytes() +} + // 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.