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
24 changes: 24 additions & 0 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// =============================================================================
Expand Down
12 changes: 12 additions & 0 deletions test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down