Skip to content

Commit

Permalink
Add benchmark to receive massive rows.
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Apr 18, 2023
1 parent faedeff commit 2f7d371
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions benchmark_test.go
Expand Up @@ -372,3 +372,49 @@ func BenchmarkQueryRawBytes(b *testing.B) {
})
}
}

// BenchmarkReceiveMassiveRows measures performance of receiving large number of rows.
func BenchmarkReceiveMassiveRows(b *testing.B) {
db := initDB(b,
"DROP TABLE IF EXISTS foo",
"CREATE TABLE foo (id INT PRIMARY KEY, val CHAR(50))")
defer db.Close()

sval := strings.Repeat("x", 40)
stmt, err := db.Prepare(`INSERT INTO foo (id, val) VALUES (?, ?)` + strings.Repeat(",(?,?)", 9))
if err != nil {
b.Errorf("failed to prepare query: %v", err)
return
}
for i := 0; i < 10_000; i += 10 {
_, err := stmt.Exec(
i, sval, i+1, sval, i+2, sval, i+3, sval, i+4, sval, i+5, sval,
i+6, sval, i+7, sval, i+8, sval, i+9, sval)
if err != nil {
b.Error(err)
return
}
}

b.Run("query", func(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
rows, err := db.Query(`SELECT id, val FROM foo`)
if err != nil {
b.Errorf("failed to select: %v", err)
return
}
for rows.Next() {
var i int
var s sql.RawBytes
err = rows.Scan(&i, &s)
if err != nil {
b.Errorf("failed to scan: %v", err)
_ = rows.Close()
return
}
}
_ = rows.Close()
}
})
}

0 comments on commit 2f7d371

Please sign in to comment.