Skip to content

Commit 2c7e779

Browse files
authored
bench: split Realistic into 20% and 40% quoted variants (#89)
* fix: remove unused generateRealisticRecords * bench: split Realistic into 20% and 40% quoted variants
1 parent 693006a commit 2c7e779

2 files changed

Lines changed: 43 additions & 8 deletions

File tree

‎benchmark_test.go‎

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,36 @@ func BenchmarkReadAll_Quoted_100K_SIMD(b *testing.B) {
139139
}
140140
}
141141

142+
// =============================================================================
143+
// ReadAll Benchmarks - Realistic CSV (20% quoted)
144+
// =============================================================================
145+
146+
func BenchmarkReadAll_Realistic20_100K_Stdlib(b *testing.B) {
147+
data := generateRealistic20CSV(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_Realistic20_100K_SIMD(b *testing.B) {
157+
data := generateRealistic20CSV(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 (40% quoted)
144168
// =============================================================================
145169

146-
func BenchmarkReadAll_Realistic_100K_Stdlib(b *testing.B) {
147-
data := generateRealisticCSV(100000, 10)
170+
func BenchmarkReadAll_Realistic40_100K_Stdlib(b *testing.B) {
171+
data := generateRealistic40CSV(100000, 10)
148172
b.SetBytes(int64(len(data)))
149173
for b.Loop() {
150174
reader := csv.NewReader(bytes.NewReader(data))
@@ -153,8 +177,8 @@ func BenchmarkReadAll_Realistic_100K_Stdlib(b *testing.B) {
153177
}
154178
}
155179

156-
func BenchmarkReadAll_Realistic_100K_SIMD(b *testing.B) {
157-
data := generateRealisticCSV(100000, 10)
180+
func BenchmarkReadAll_Realistic40_100K_SIMD(b *testing.B) {
181+
data := generateRealistic40CSV(100000, 10)
158182
b.SetBytes(int64(len(data)))
159183
for b.Loop() {
160184
reader := NewReader(bytes.NewReader(data))

‎test_helpers_test.go‎

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

206-
// generateRealisticCSV generates CSV with 4/10 quoted fields containing commas (~40%).
206+
// generateRealistic20CSV generates CSV with 2/10 quoted fields containing commas (~20%).
207+
// Row template: "Alice, Smith",30,Tokyo,engineer,100,Japan,active,42,"New York, US",2024
208+
// Cols 0,8 are quoted.
209+
func generateRealistic20CSV(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,"New York, US",2024`)
213+
buf.WriteByte('\n')
214+
}
215+
return buf.Bytes()
216+
}
217+
218+
// generateRealistic40CSV generates CSV with 4/10 quoted fields containing commas (~40%).
207219
// Row template: "Alice, Smith",30,"Tokyo, JP",engineer,100,"Japan, Asia",active,42,"New York, US",2024
208-
// Cols 0,2,5,8 are quoted; this exercises the prefixXOR / PCLMULQDQ hot path
209-
// without the all-quoted overhead.
210-
func generateRealisticCSV(numRows, _ int) []byte {
220+
// Cols 0,2,5,8 are quoted.
221+
func generateRealistic40CSV(numRows, _ int) []byte {
211222
var buf bytes.Buffer
212223
for i := 0; i < numRows; i++ {
213224
buf.WriteString(`"Alice, Smith",30,"Tokyo, JP",engineer,100,"Japan, Asia",active,42,"New York, US",2024`)

0 commit comments

Comments
 (0)