diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2026-09-15 13:26:02 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2026-09-15 13:35:09 +0200 |
| commit | 8d85366bee9c59486b445a9cc21a6271e7244e0a (patch) | |
| tree | 20d804823e93f048ef150882cf7412d664efa927 /benchmark/benchmark_test.go | |
| parent | 92551b9a7b2825b76cb62ad7874ebef8e0c1e9c9 (diff) | |
| download | go-oblast-8d85366bee9c59486b445a9cc21a6271e7244e0a.tar.gz | |
add func Select/SelectOne/SelectOneOrNone
Diffstat (limited to 'benchmark/benchmark_test.go')
| -rw-r--r-- | benchmark/benchmark_test.go | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/benchmark/benchmark_test.go b/benchmark/benchmark_test.go index 4549962..487b9c5 100644 --- a/benchmark/benchmark_test.go +++ b/benchmark/benchmark_test.go @@ -174,6 +174,46 @@ func BenchmarkORMSelectMany(b *testing.B) { } } +func BenchmarkORMSelectManyValues(b *testing.B) { + db, _ := makeSqliteTestDB(b, totalRecordCountForSelect) + + // test with different sizes of resultsets (N=1 is an OLTP-like workload, + // then the larger N lean more towards the OLAP side of things) + for _, batchSize := range batchSizesForSelect { + b.Run("N="+strconv.Itoa(batchSize), func(b *testing.B) { + // prepare the functions that will be benched + query := `SELECT message FROM entries WHERE id < ` + strconv.Itoa(batchSize) + selectWithOblast := func(b *testing.B) { + messages := must.Return(oblast.Select[string](noctx, db, query).Collect())(b) + assert.Equal(b, len(messages), batchSize) + } + selectWithSqlite := func(b *testing.B) { + var count int + rows := must.Return(db.Query(query))(b) //nolint:rowserrcheck // false positive + var message string + for rows.Next() { + must.Succeed(b, rows.Scan(&message)) + count++ + } + must.Succeed(b, rows.Close()) + assert.Equal(b, count, batchSize) + } + + // run actual benchmark + b.Run("via Oblast", func(b *testing.B) { + for b.Loop() { + selectWithOblast(b) + } + }) + b.Run("just SQLite", func(b *testing.B) { + for b.Loop() { + selectWithSqlite(b) + } + }) + }) + } +} + func BenchmarkORMSelectOne(b *testing.B) { db, dsn := makeSqliteTestDB(b, totalRecordCountForSelect) @@ -258,6 +298,37 @@ func BenchmarkORMSelectOne(b *testing.B) { }) } +func BenchmarkORMSelectOneValue(b *testing.B) { + db, _ := makeSqliteTestDB(b, totalRecordCountForSelect) + + // grab a "random" record from the DB, not just the first or the last + recordID := min(totalRecordCountForSelect*2/3, totalRecordCountForSelect) + + // prepare the functions that will be benched + query := `SELECT message FROM entries WHERE id = ` + strconv.Itoa(recordID) + selectWithOblast := func(b *testing.B) { + message := must.Return(oblast.SelectOne[string](noctx, db, query))(b) + assert.Equal(b, len(message), 71) + } + selectWithSqlite := func(b *testing.B) { + var message string + must.Succeed(b, db.QueryRow(query).Scan(&message)) + assert.Equal(b, len(message), 71) + } + + // run actual benchmark + b.Run("via Oblast", func(b *testing.B) { + for b.Loop() { + selectWithOblast(b) + } + }) + b.Run("just SQLite", func(b *testing.B) { + for b.Loop() { + selectWithSqlite(b) + } + }) +} + func BenchmarkORMInsertAndDelete(b *testing.B) { db, dsn := makeSqliteTestDB(b, 0) |
