Update benchmarks to test ksql on its most common use-case

Before this commit we were not benchmarking ksql with the
"omit-select" feature.

This could lead people to say that this feature is actually
expensive, but it really isn't so I just updated the benchmarks
to always run with this feature.

Before doing this change I actually put both features together
on the benchmark to compare them and these are the results:

```
ksql/sql-adapter/single-row-12               17186   143286 ns/op
ksql/sql-adapter-with-omit/single-row-12     16502   142893 ns/op

ksql/sql-adapter/multiple-rows-12            15361   153890 ns/op
ksql/sql-adapter-with-omit/multiple-rows-12  15360   156075 ns/op

ksql/pgx-adapter/single-row-12               33894    68332 ns/op
ksql/pgx-adapter-with-omit/single-row-12     34563    68861 ns/op

ksql/pgx-adapter/multiple-rows-12            29677    79196 ns/op
ksql/pgx-adapter-with-omit/multiple-rows-12  28934    80422 ns/op
```

Please note that benchmarks usually run slighly slower or faster
on each attempt, so small differences like the ones presented
above are really hard to interpret.
This commit is contained in:
Vinícius Garcia 2022-05-31 09:19:22 -03:00
parent ed0327babe
commit be9f686a9a
2 changed files with 28 additions and 28 deletions

View File

@ -705,31 +705,31 @@ goos: linux
goarch: amd64
pkg: github.com/vingarcia/ksql/benchmarks
cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
BenchmarkInsert/ksql/sql-adapter/insert-one-12 7966 630421 ns/op
BenchmarkInsert/ksql/pgx-adapter/insert-one-12 10000 557143 ns/op
BenchmarkInsert/sql/insert-one-12 9296 627834 ns/op
BenchmarkInsert/sql/prep-statements/insert-one-12 10836 561999 ns/op
BenchmarkInsert/sqlx/insert-one-12 9686 638942 ns/op
BenchmarkInsert/pgxpool/insert-one-12 10000 567271 ns/op
BenchmarkInsert/gorm/insert-one-12 9163 669396 ns/op
BenchmarkQuery/ksql/sql-adapter/single-row-12 42124 149014 ns/op
BenchmarkQuery/ksql/sql-adapter/multiple-rows-12 38244 157941 ns/op
BenchmarkQuery/ksql/pgx-adapter/single-row-12 88578 70401 ns/op
BenchmarkQuery/ksql/pgx-adapter/multiple-rows-12 74156 81391 ns/op
BenchmarkQuery/sql/single-row-12 42818 142127 ns/op
BenchmarkQuery/sql/multiple-rows-12 38788 148733 ns/op
BenchmarkQuery/sql/prep-statements/single-row-12 85287 69135 ns/op
BenchmarkQuery/sql/prep-statements/multiple-rows-12 80311 73877 ns/op
BenchmarkQuery/sqlx/single-row-12 41606 146031 ns/op
BenchmarkQuery/sqlx/multiple-rows-12 39592 154469 ns/op
BenchmarkQuery/pgxpool/single-row-12 88638 66996 ns/op
BenchmarkQuery/pgxpool/multiple-rows-12 83715 71674 ns/op
BenchmarkQuery/gorm/single-row-12 80734 73582 ns/op
BenchmarkQuery/gorm/multiple-rows-12 63243 95192 ns/op
BenchmarkInsert/ksql/sql-adapter/insert-one-12 9261 619007 ns/op
BenchmarkInsert/ksql/pgx-adapter/insert-one-12 10000 553864 ns/op
BenchmarkInsert/sql/insert-one-12 9285 615861 ns/op
BenchmarkInsert/sql/prep-statements/insert-one-12 10000 537445 ns/op
BenchmarkInsert/sqlx/insert-one-12 9045 621774 ns/op
BenchmarkInsert/pgxpool/insert-one-12 10000 538560 ns/op
BenchmarkInsert/gorm/insert-one-12 8785 655420 ns/op
BenchmarkQuery/ksql/sql-adapter/single-row-12 39871 142689 ns/op
BenchmarkQuery/ksql/sql-adapter/multiple-rows-12 38475 156496 ns/op
BenchmarkQuery/ksql/pgx-adapter/single-row-12 93624 68686 ns/op
BenchmarkQuery/ksql/pgx-adapter/multiple-rows-12 76512 79323 ns/op
BenchmarkQuery/sql/single-row-12 42637 142758 ns/op
BenchmarkQuery/sql/multiple-rows-12 40566 149877 ns/op
BenchmarkQuery/sql/prep-statements/single-row-12 90952 68049 ns/op
BenchmarkQuery/sql/prep-statements/multiple-rows-12 81711 72090 ns/op
BenchmarkQuery/sqlx/single-row-12 43371 142076 ns/op
BenchmarkQuery/sqlx/multiple-rows-12 39952 150358 ns/op
BenchmarkQuery/pgxpool/single-row-12 93656 67181 ns/op
BenchmarkQuery/pgxpool/multiple-rows-12 85225 71349 ns/op
BenchmarkQuery/gorm/single-row-12 84655 71672 ns/op
BenchmarkQuery/gorm/multiple-rows-12 68212 88490 ns/op
PASS
ok github.com/vingarcia/ksql/benchmarks 146.098s
Benchmark executed at: 2022-01-20
Benchmark executed on commit: 8cd7a37da9c74f6f365665cd0c20d24843284421
ok github.com/vingarcia/ksql/benchmarks 140.180s
Benchmark executed at: 2022-05-31
Benchmark executed on commit: ed0327babe06a657b2348d2e9d5e5ea824a71fc0
```
## Running the ksql tests (for contributors)

View File

@ -310,7 +310,7 @@ func BenchmarkQuery(b *testing.B) {
b.Run("single-row", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var user User
err := ksqlDB.QueryOne(ctx, &user, `SELECT id, name, age FROM users OFFSET $1 LIMIT 1`, i%100)
err := ksqlDB.QueryOne(ctx, &user, `FROM users OFFSET $1 LIMIT 1`, i%100)
if err != nil {
b.Fatalf("query error: %s", err.Error())
}
@ -320,7 +320,7 @@ func BenchmarkQuery(b *testing.B) {
b.Run("multiple-rows", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var users []User
err := ksqlDB.Query(ctx, &users, `SELECT id, name, age FROM users OFFSET $1 LIMIT 10`, i%90)
err := ksqlDB.Query(ctx, &users, `FROM users OFFSET $1 LIMIT 10`, i%90)
if err != nil {
b.Fatalf("query error: %s", err.Error())
}
@ -352,7 +352,7 @@ func BenchmarkQuery(b *testing.B) {
b.Run("single-row", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var user User
err := kpgxDB.QueryOne(ctx, &user, `SELECT id, name, age FROM users OFFSET $1 LIMIT 1`, i%100)
err := kpgxDB.QueryOne(ctx, &user, `FROM users OFFSET $1 LIMIT 1`, i%100)
if err != nil {
b.Fatalf("query error: %s", err.Error())
}
@ -362,7 +362,7 @@ func BenchmarkQuery(b *testing.B) {
b.Run("multiple-rows", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var users []User
err := kpgxDB.Query(ctx, &users, `SELECT id, name, age FROM users OFFSET $1 LIMIT 10`, i%90)
err := kpgxDB.Query(ctx, &users, `FROM users OFFSET $1 LIMIT 10`, i%90)
if err != nil {
b.Fatalf("query error: %s", err.Error())
}