Skip to content

Commit 18fb2b0

Browse files
authored
bench: add Realistic10 (10% quoted) benchmark case (#90)
1 parent 2c7e779 commit 18fb2b0

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

benchmark_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,30 @@ func BenchmarkReadAll_Quoted_100K_SIMD(b *testing.B) {
139139
}
140140
}
141141

142+
// =============================================================================
143+
// ReadAll Benchmarks - Realistic CSV (10% quoted)
144+
// =============================================================================
145+
146+
func BenchmarkReadAll_Realistic10_100K_Stdlib(b *testing.B) {
147+
data := generateRealistic10CSV(100000, 10)
148+
b.SetBytes(int64(len(data)))
149+
for b.Loop() {
150+
reader := csv.NewReader(bytes.NewReader(data))
151+
reader.FieldsPerRecord = -1
152+
_, _ = reader.ReadAll()
153+
}
154+
}
155+
156+
func BenchmarkReadAll_Realistic10_100K_SIMD(b *testing.B) {
157+
data := generateRealistic10CSV(100000, 10)
158+
b.SetBytes(int64(len(data)))
159+
for b.Loop() {
160+
reader := NewReader(bytes.NewReader(data))
161+
reader.FieldsPerRecord = -1
162+
_, _ = reader.ReadAll()
163+
}
164+
}
165+
142166
// =============================================================================
143167
// ReadAll Benchmarks - Realistic CSV (20% quoted)
144168
// =============================================================================

test_helpers_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ func generateEscapedQuotesCSV(numRows, numCols int) []byte {
203203
return buf.Bytes()
204204
}
205205

206+
// generateRealistic10CSV generates CSV with 1/10 quoted fields containing commas (~10%).
207+
// Row template: "Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,NewYork,2024
208+
// Col 0 is quoted.
209+
func generateRealistic10CSV(numRows, _ int) []byte {
210+
var buf bytes.Buffer
211+
for i := 0; i < numRows; i++ {
212+
buf.WriteString(`"Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,NewYork,2024`)
213+
buf.WriteByte('\n')
214+
}
215+
return buf.Bytes()
216+
}
217+
206218
// generateRealistic20CSV generates CSV with 2/10 quoted fields containing commas (~20%).
207219
// Row template: "Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,"New York, US",2024
208220
// Cols 0,8 are quoted.

0 commit comments

Comments
 (0)