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
32 changes: 28 additions & 4 deletions benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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))
Expand Down
34 changes: 15 additions & 19 deletions test_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down Expand Up @@ -275,18 +286,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
}