Skip to content

Commit

Permalink
Fix benchmark inconsistencies: sqlc, pgx, pgx_pool, sqlx (issue #97) (#…
Browse files Browse the repository at this point in the history
…98)

* Update dependancies.

* Revert breaking update in upper 4.8.0.

* Fix sqlc benchmark queries to others.
  • Loading branch information
JakubCzarlinski authored Oct 15, 2024
1 parent f8fb809 commit 5fb4d8e
Show file tree
Hide file tree
Showing 19 changed files with 588 additions and 728 deletions.
5 changes: 3 additions & 2 deletions bench/dbr.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bench

import (
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

dbrware "github.com/gocraft/dbr/v2"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
)

var columns = []string{"name", "title", "fax", "web", "age", "right", "counter"}
Expand Down
5 changes: 3 additions & 2 deletions bench/ent.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ package bench

import (
"database/sql"
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

"entgo.io/ent/dialect"
entsql "entgo.io/ent/dialect/sql"
entdb "github.com/efectn/go-orm-benchmarks/bench/ent"
"github.com/efectn/go-orm-benchmarks/bench/ent/model"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
)

type Ent struct {
Expand Down
5 changes: 3 additions & 2 deletions bench/godb.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bench

import (
"testing"

"github.com/efectn/go-orm-benchmarks/helper"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
godbware "github.com/samonzeweb/godb"
"github.com/samonzeweb/godb/adapters/postgresql"
"testing"
)

type Godb struct {
Expand Down
5 changes: 3 additions & 2 deletions bench/gorp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package bench

import (
"database/sql"
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

_ "github.com/jackc/pgx/v4/stdlib"
"github.com/efectn/go-orm-benchmarks/helper"

_ "github.com/jackc/pgx/v5/stdlib"
_ "github.com/lib/pq"
gorpware "gopkg.in/gorp.v1"
)
Expand Down
5 changes: 3 additions & 2 deletions bench/pgx.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package bench

import (
"github.com/efectn/go-orm-benchmarks/helper"
pgxdb "github.com/jackc/pgx/v4"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"
pgxdb "github.com/jackc/pgx/v5"
)

type Pgx struct {
Expand Down
9 changes: 5 additions & 4 deletions bench/pgx_pool.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package bench

import (
"github.com/efectn/go-orm-benchmarks/helper"
pgxdb "github.com/jackc/pgx/v4"
"github.com/jackc/pgx/v4/pgxpool"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"
pgxdb "github.com/jackc/pgx/v5"
"github.com/jackc/pgx/v5/pgxpool"
)

type PgxPool struct {
Expand All @@ -22,7 +23,7 @@ func (pgx *PgxPool) Name() string {

func (pgx *PgxPool) Init() error {
var err error
pgx.conn, err = pgxpool.Connect(ctx, helper.OrmSource)
pgx.conn, err = pgxpool.New(ctx, helper.OrmSource)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions bench/pop.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bench

import (
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

popware "github.com/gobuffalo/pop/v6"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
)

type Pop struct {
Expand Down
5 changes: 3 additions & 2 deletions bench/reform.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package bench

import (
"database/sql"
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

r "github.com/efectn/go-orm-benchmarks/bench/reform"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
"gopkg.in/reform.v1/dialects/postgresql"

reformware "gopkg.in/reform.v1"
Expand Down
5 changes: 3 additions & 2 deletions bench/sqlboiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package bench

import (
"database/sql"
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

models "github.com/efectn/go-orm-benchmarks/bench/sqlboiler"
_ "github.com/jackc/pgx/v4/stdlib"
_ "github.com/jackc/pgx/v5/stdlib"
"github.com/volatiletech/sqlboiler/v4/boil"
"github.com/volatiletech/sqlboiler/v4/queries/qm"
)
Expand Down
82 changes: 52 additions & 30 deletions bench/sqlc.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package bench

import (
"database/sql"
"github.com/efectn/go-orm-benchmarks/helper"
"testing"

"github.com/efectn/go-orm-benchmarks/helper"

"github.com/efectn/go-orm-benchmarks/bench/sqlc/db"
"github.com/jackc/pgx/v5"
)

type Sqlc struct {
helper.ORMInterface
conn *db.Queries
db *sql.DB
db *pgx.Conn
}

func CreateSqlc() helper.ORMInterface {
Expand All @@ -24,7 +25,7 @@ func (sqlc *Sqlc) Name() string {

func (sqlc *Sqlc) Init() error {
var err error
sqlc.db, err = sql.Open("pgx", helper.OrmSource)
sqlc.db, err = pgx.Connect(ctx, helper.OrmSource)
if err != nil {
return err
}
Expand All @@ -35,18 +36,39 @@ func (sqlc *Sqlc) Init() error {
}

func (sqlc *Sqlc) Close() error {
return sqlc.db.Close()
return sqlc.db.Close(ctx)
}

func (sqlc *Sqlc) Insert(b *testing.B) {
m := NewModel()

args := db.CreateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Web: m.Web,
Age: int32(m.Age),
Right: m.Right,
Counter: m.Counter,
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
m.Id = 0
_, err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
err := sqlc.conn.CreateModel(ctx, args)
if err != nil {
helper.SetError(b, sqlc.Name(), "Insert", err.Error())
}
}
}

func (sqlc *Sqlc) InsertMulti(b *testing.B) {
ms := make([]db.InsertMultiParams, 0, 100)
m := NewModel()
for i := 0; i < 100; i++ {
ms = append(ms, db.InsertMultiParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Expand All @@ -55,20 +77,22 @@ func (sqlc *Sqlc) Insert(b *testing.B) {
Right: m.Right,
Counter: m.Counter,
})
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := sqlc.conn.InsertMulti(ctx, ms)
if err != nil {
helper.SetError(b, sqlc.Name(), "Insert", err.Error())
helper.SetError(b, sqlc.Name(), "InsertMulti", err.Error())
}
}
}

func (sqlc *Sqlc) InsertMulti(b *testing.B) {
helper.SetError(b, sqlc.Name(), "InsertMulti", "bulk-insert is not supported")
}

func (sqlc *Sqlc) Update(b *testing.B) {
m := NewModel()

_, err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Expand All @@ -81,20 +105,21 @@ func (sqlc *Sqlc) Update(b *testing.B) {
helper.SetError(b, sqlc.Name(), "Update", err.Error())
}

args := db.UpdateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Web: m.Web,
Age: int32(m.Age),
Right: m.Right,
Counter: m.Counter,
ID: int32(m.Id),
}
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
err := sqlc.conn.UpdateModel(ctx, db.UpdateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Web: m.Web,
Age: int32(m.Age),
Right: m.Right,
Counter: m.Counter,
ID: int32(m.Id),
})
err := sqlc.conn.UpdateModel(ctx, args)
if err != nil {
helper.SetError(b, sqlc.Name(), "Update", err.Error())
}
Expand All @@ -104,7 +129,7 @@ func (sqlc *Sqlc) Update(b *testing.B) {
func (sqlc *Sqlc) Read(b *testing.B) {
m := NewModel()

output, err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Expand All @@ -113,7 +138,7 @@ func (sqlc *Sqlc) Read(b *testing.B) {
Right: m.Right,
Counter: m.Counter,
})
m.Id = int(output.ID)
m.Id = 1
if err != nil {
helper.SetError(b, sqlc.Name(), "Read", err.Error())
}
Expand All @@ -135,7 +160,7 @@ func (sqlc *Sqlc) ReadSlice(b *testing.B) {
for i := 0; i < 100; i++ {
m.Id = 0

_, err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
err := sqlc.conn.CreateModel(ctx, db.CreateModelParams{
Name: m.Name,
Title: m.Title,
Fax: m.Fax,
Expand All @@ -153,10 +178,7 @@ func (sqlc *Sqlc) ReadSlice(b *testing.B) {
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := sqlc.conn.ListModels(ctx, db.ListModelsParams{
ID: 0,
Limit: 100,
})
_, err := sqlc.conn.ListModels(ctx)
if err != nil {
helper.SetError(b, sqlc.Name(), "ReadSlice", err.Error())
}
Expand Down
48 changes: 48 additions & 0 deletions bench/sqlc/db/copyfrom.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 5fb4d8e

Please sign in to comment.