Skip to content

Commit 2f7d371

Browse files
committed
Add benchmark to receive massive rows.
1 parent faedeff commit 2f7d371

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

benchmark_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,49 @@ func BenchmarkQueryRawBytes(b *testing.B) {
372372
})
373373
}
374374
}
375+
376+
// BenchmarkReceiveMassiveRows measures performance of receiving large number of rows.
377+
func BenchmarkReceiveMassiveRows(b *testing.B) {
378+
db := initDB(b,
379+
"DROP TABLE IF EXISTS foo",
380+
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))")
381+
defer db.Close()
382+
383+
sval := strings.Repeat("x", 40)
384+
stmt, err := db.Prepare(`INSERT INTO foo (id, val) VALUES (?, ?)` + strings.Repeat(",(?,?)", 9))
385+
if err != nil {
386+
b.Errorf("failed to prepare query: %v", err)
387+
return
388+
}
389+
for i := 0; i < 10_000; i += 10 {
390+
_, err := stmt.Exec(
391+
i, sval, i+1, sval, i+2, sval, i+3, sval, i+4, sval, i+5, sval,
392+
i+6, sval, i+7, sval, i+8, sval, i+9, sval)
393+
if err != nil {
394+
b.Error(err)
395+
return
396+
}
397+
}
398+
399+
b.Run("query", func(b *testing.B) {
400+
b.ReportAllocs()
401+
for i := 0; i < b.N; i++ {
402+
rows, err := db.Query(`SELECT id, val FROM foo`)
403+
if err != nil {
404+
b.Errorf("failed to select: %v", err)
405+
return
406+
}
407+
for rows.Next() {
408+
var i int
409+
var s sql.RawBytes
410+
err = rows.Scan(&i, &s)
411+
if err != nil {
412+
b.Errorf("failed to scan: %v", err)
413+
_ = rows.Close()
414+
return
415+
}
416+
}
417+
_ = rows.Close()
418+
}
419+
})
420+
}

0 commit comments

Comments
 (0)