Skip to content

Commit 85e398e

Browse files
committed
sqlite: add BenchmarkQueryRows100MixedTypes
Signed-off-by: Brad Fitzpatrick <[email protected]>
1 parent e8d4f2c commit 85e398e

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

sqlite_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,47 @@ func BenchmarkPersist(b *testing.B) {
911911
}
912912
}
913913

914+
func BenchmarkQueryRows100MixedTypes(b *testing.B) {
915+
b.ReportAllocs()
916+
ctx := context.Background()
917+
db := openTestDB(b)
918+
conn, err := db.Conn(ctx)
919+
if err != nil {
920+
b.Fatal(err)
921+
}
922+
err = ExecScript(conn, `BEGIN;
923+
CREATE TABLE t (id INTEGER);
924+
COMMIT;`)
925+
if err != nil {
926+
b.Fatal(err)
927+
}
928+
for i := 0; i < 100; i++ {
929+
if _, err := db.Exec("INSERT INTO t (id) VALUES (?)", i); err != nil {
930+
b.Fatal(err)
931+
}
932+
}
933+
b.ResetTimer()
934+
935+
ctx = WithPersist(ctx)
936+
937+
var id int
938+
var raw sql.RawBytes
939+
for i := 0; i < b.N; i++ {
940+
rows, err := db.QueryContext(ctx, "SELECT id, 'hello world some string' FROM t")
941+
if err != nil {
942+
b.Fatal(err)
943+
}
944+
for rows.Next() {
945+
if err := rows.Scan(&id, &raw); err != nil {
946+
b.Fatal(err)
947+
}
948+
}
949+
if err := rows.Err(); err != nil {
950+
b.Fatal(err)
951+
}
952+
}
953+
}
954+
914955
func BenchmarkEmptyExec(b *testing.B) {
915956
b.ReportAllocs()
916957
ctx := context.Background()

0 commit comments

Comments
 (0)