Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ All package run in no-cache mode.
- [sqlboiler](https://github.com/volatiletech/sqlboiler)
- [sqlx](https://github.com/jmoiron/sqlx)
- [pgx](https://github.com/jackc/pgx)
- [zorm](https://gitee.com/chunanyong/zorm)

See [`go.mod`](go.mod) for their latest versions.

Expand Down
39 changes: 38 additions & 1 deletion benchs/models.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package benchs

import models "github.com/efectn/go-orm-benchmarks/benchs/sqlboiler"
import (
"gitee.com/chunanyong/zorm"
models "github.com/efectn/go-orm-benchmarks/benchs/sqlboiler"
)

// Model for GORM, GORP, Beego, Bun, Pg, Raw, Sqlc, Ent
type Model struct {
Expand Down Expand Up @@ -173,3 +176,37 @@ func NewModel6() *models.Model {

return m
}

// Model for zorm
type Model7 struct {
zorm.EntityStruct
ID int `column:"id"`
Name string `column:"name"`
Title string `column:"title"`
Fax string `column:"fax"`
Web string `column:"web"`
Age int `column:"age"`
Right bool `column:"\"right\""`
Counter int64 `column:"counter"`
}

func (entity *Model7) GetTableName() string {
return "models"
}

func (entity *Model7) GetPKColumnName() string {
return "id"
}

func NewModel7() *Model7 {
m := new(Model7)
m.Name = "Orm Benchmark"
m.Title = "Just a Benchmark for fun"
m.Fax = "99909990"
m.Web = "http://blog.milkpod29.me"
m.Age = 100
m.Right = true
m.Counter = 1000

return m
}
2 changes: 1 addition & 1 deletion benchs/rel.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func init() {
CheckErr(err)

// Disable debug logging
rel.Instrumentation(func(ctx context.Context, op string, message string) func(err error) {
rel.Instrumentation(func(ctx context.Context, op string, message string, args ...any) func(err error) {
return func(err error) {
CheckErr(err)
}
Expand Down
124 changes: 124 additions & 0 deletions benchs/zorm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
package benchs

import (
"context"

"gitee.com/chunanyong/zorm"
_ "github.com/lib/pq"
)

var (
zormCtx = context.Background()
readFinder = zorm.NewFinder().Append("SELECT * FROM models WHERE id = 1")
readSliceFinder = zorm.NewFinder().Append("SELECT * FROM models WHERE id > 0")
page = &zorm.Page{PageNo: 1, PageSize: 100}
)

func init() {
st := NewSuite("zorm")
readFinder.InjectionCheck = false
readSliceFinder.InjectionCheck = false
readSliceFinder.SelectTotalCount = false
st.InitF = func() {
st.AddBenchmark("Insert", 200*OrmMulti, ZormInsert)
st.AddBenchmark("MultiInsert 100 row", 200*OrmMulti, ZormInsertMulti)
st.AddBenchmark("Update", 200*OrmMulti, ZormUpdate)
st.AddBenchmark("Read", 200*OrmMulti, ZormRead)
st.AddBenchmark("MultiRead limit 100", 200*OrmMulti, ZormReadSlice)

dbDaoConfig := zorm.DataSourceConfig{
DSN: OrmSource,
DriverName: "postgres",
Dialect: "postgresql",
MaxOpenConns: OrmMaxConn,
MaxIdleConns: OrmMaxIdle,
SlowSQLMillis: -1,
DisableTransaction: true,
}
_, err := zorm.NewDBDao(&dbDaoConfig)
CheckErr(err)
}
}

func ZormInsert(b *B) {
var m *Model7
WrapExecute(b, func() {
InitDB()
m = NewModel7()
})

for i := 0; i < b.N; i++ {
m.ID = 0
_, err := zorm.Insert(zormCtx, m)
CheckErr(err, b)
}
}

func ZormInsertMulti(b *B) {
var ms []zorm.IEntityStruct
WrapExecute(b, func() {
InitDB()
ms = make([]zorm.IEntityStruct, 0, 100)
for i := 0; i < 100; i++ {
ms = append(ms, NewModel7())
}
})

for i := 0; i < b.N; i++ {
for _, m := range ms {
m7, _ := m.(*Model7)
m7.ID = 0
}
_, err := zorm.InsertSlice(zormCtx, ms)
CheckErr(err, b)
}
}

func ZormUpdate(b *B) {
var m *Model7
WrapExecute(b, func() {
InitDB()
m = NewModel7()
_, err := zorm.Insert(zormCtx, m)
CheckErr(err, b)
})

for i := 0; i < b.N; i++ {
_, err := zorm.Update(zormCtx, m)
CheckErr(err, b)
}
}

func ZormRead(b *B) {
var m *Model7
WrapExecute(b, func() {
InitDB()
m = NewModel7()
_, err := zorm.Insert(zormCtx, m)
CheckErr(err, b)
})

for i := 0; i < b.N; i++ {
_, err := zorm.QueryRow(zormCtx, readFinder, m)
CheckErr(err, b)
}
}

func ZormReadSlice(b *B) {
var m *Model7
WrapExecute(b, func() {
InitDB()
m = NewModel7()
for i := 0; i < 100; i++ {
m.ID = 0
_, err := zorm.Insert(zormCtx, m)
CheckErr(err, b)
}
})

for i := 0; i < b.N; i++ {
var models []Model7
err := zorm.Query(zormCtx, readSliceFinder, &models, page)
CheckErr(err, b)
}
}
104 changes: 53 additions & 51 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,34 @@ module github.com/efectn/go-orm-benchmarks
go 1.18

require (
entgo.io/ent v0.10.1
entgo.io/ent v0.11.8
gitee.com/chunanyong/zorm v1.6.6
github.com/astaxie/beego v1.12.3
github.com/friendsofgo/errors v0.9.2
github.com/go-pg/pg/v10 v10.10.6
github.com/go-rel/postgres v0.7.0
github.com/go-rel/rel v0.34.0
github.com/gobuffalo/pop/v6 v6.0.3
github.com/go-pg/pg/v10 v10.11.0
github.com/go-rel/postgres v0.8.0
github.com/go-rel/rel v0.39.0
github.com/gobuffalo/pop/v6 v6.1.1
github.com/gocraft/dbr/v2 v2.7.3
github.com/jackc/pgx/v4 v4.16.1
github.com/jackc/pgx/v4 v4.18.0
github.com/jmoiron/sqlx v1.3.5
github.com/lib/pq v1.10.6
github.com/lib/pq v1.10.7
github.com/samonzeweb/godb v1.0.15
github.com/upper/db/v4 v4.5.2
github.com/uptrace/bun v1.1.5
github.com/uptrace/bun/dialect/pgdialect v1.1.5
github.com/uptrace/bun/driver/pgdriver v1.1.5
github.com/volatiletech/sqlboiler/v4 v4.11.0
github.com/upper/db/v4 v4.6.0
github.com/uptrace/bun v1.1.11
github.com/uptrace/bun/dialect/pgdialect v1.1.11
github.com/uptrace/bun/driver/pgdriver v1.1.11
github.com/volatiletech/sqlboiler/v4 v4.14.1
github.com/volatiletech/strmangle v0.0.4
gopkg.in/gorp.v1 v1.7.2
gopkg.in/reform.v1 v1.5.1
gorm.io/driver/postgres v1.3.6
gorm.io/gorm v1.23.5
xorm.io/xorm v1.3.0
gorm.io/driver/postgres v1.4.5
gorm.io/gorm v1.24.5
xorm.io/xorm v1.3.2
)

require (
ariga.io/atlas v0.3.7-0.20220303204946-787354f533c3 // indirect
ariga.io/atlas v0.9.1-0.20230119145809-92243f7c55cb // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
Expand All @@ -38,53 +39,54 @@ require (
github.com/fatih/structs v1.1.0 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-pg/zerochecker v0.2.0 // indirect
github.com/go-rel/sql v0.10.0 // indirect
github.com/go-sql-driver/mysql v1.6.0 // indirect
github.com/gobuffalo/envy v1.10.1 // indirect
github.com/gobuffalo/fizz v1.14.0 // indirect
github.com/gobuffalo/flect v0.2.5 // indirect
github.com/gobuffalo/github_flavored_markdown v1.1.1 // indirect
github.com/gobuffalo/helpers v0.6.4 // indirect
github.com/gobuffalo/nulls v0.4.1 // indirect
github.com/gobuffalo/plush/v4 v4.1.11 // indirect
github.com/gobuffalo/tags/v3 v3.1.2 // indirect
github.com/gobuffalo/validate/v3 v3.3.1 // indirect
github.com/goccy/go-json v0.9.7 // indirect
github.com/gofrs/uuid v4.2.0+incompatible // indirect
github.com/go-rel/sql v0.11.0 // indirect
github.com/go-sql-driver/mysql v1.7.0 // indirect
github.com/gobuffalo/envy v1.10.2 // indirect
github.com/gobuffalo/fizz v1.14.4 // indirect
github.com/gobuffalo/flect v1.0.0 // indirect
github.com/gobuffalo/github_flavored_markdown v1.1.3 // indirect
github.com/gobuffalo/helpers v0.6.7 // indirect
github.com/gobuffalo/nulls v0.4.2 // indirect
github.com/gobuffalo/plush/v4 v4.1.18 // indirect
github.com/gobuffalo/tags/v3 v3.1.4 // indirect
github.com/gobuffalo/validate/v3 v3.3.3 // indirect
github.com/goccy/go-json v0.8.1 // indirect
github.com/gofrs/uuid v4.3.1+incompatible // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/go-cmp v0.5.6 // indirect
github.com/google/go-cmp v0.5.8 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl/v2 v2.10.0 // indirect
github.com/hashicorp/hcl/v2 v2.13.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgconn v1.12.1 // indirect
github.com/jackc/pgconn v1.14.0 // indirect
github.com/jackc/pgio v1.0.0 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgproto3/v2 v2.3.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
github.com/jackc/pgtype v1.11.0 // indirect
github.com/jackc/puddle v1.2.1 // indirect
github.com/jackc/pgproto3/v2 v2.3.2 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/puddle v1.3.0 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jinzhu/now v1.1.4 // indirect
github.com/joho/godotenv v1.4.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/luna-duclos/instrumentedsql v1.1.3 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-sqlite3 v2.0.3+incompatible // indirect
github.com/microcosm-cc/bluemonday v1.0.18 // indirect
github.com/microcosm-cc/bluemonday v1.0.20 // indirect
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/rogpeppe/go-internal v1.9.0 // indirect
github.com/segmentio/fasthash v1.0.3 // indirect
github.com/serenize/snaker v0.0.0-20201027110005-a7ad2135616e // indirect
github.com/sergi/go-diff v1.2.0 // indirect
github.com/sourcegraph/annotate v0.0.0-20160123013949-f4cad6c6324d // indirect
github.com/sourcegraph/syntaxhighlight v0.0.0-20170531221838-bd320f5d308e // indirect
github.com/spf13/cast v1.4.1 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/syndtr/goleveldb v1.0.0 // indirect
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
github.com/vmihailenco/bufpool v0.1.11 // indirect
Expand All @@ -93,14 +95,14 @@ require (
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
github.com/volatiletech/inflect v0.0.1 // indirect
github.com/zclconf/go-cty v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220511200225-c6db032c6c88 // indirect
golang.org/x/mod v0.5.1 // indirect
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220411194840-2f41105eb62f // indirect
golang.org/x/crypto v0.6.0 // indirect
golang.org/x/mod v0.7.0 // indirect
golang.org/x/net v0.6.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
mellium.im/sasl v0.2.1 // indirect
xorm.io/builder v0.3.10 // indirect
mellium.im/sasl v0.3.1 // indirect
xorm.io/builder v0.3.11-0.20220531020008-1bd24a7dc978 // indirect
)
Loading