Skip to content

Commit

Permalink
add jet
Browse files Browse the repository at this point in the history
  • Loading branch information
Liooo committed Jan 4, 2024
1 parent 27a01cf commit 833e3d1
Show file tree
Hide file tree
Showing 11 changed files with 312 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -27,6 +27,7 @@ All package run in no-cache mode.
- [pgx](https://github.com/jackc/pgx)
- [zorm](https://gitee.com/chunanyong/zorm)
- [gen](https://gorm.io/gen/index.html)
- [jet](https://github.com/go-jet/jet)

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

Expand Down
144 changes: 144 additions & 0 deletions bench/jet.go
@@ -0,0 +1,144 @@
package bench

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

"github.com/efectn/go-orm-benchmarks/bench/jet/test/public/model"
. "github.com/efectn/go-orm-benchmarks/bench/jet/test/public/table"
jetpg "github.com/go-jet/jet/v2/postgres"

"testing"
)

type Jet struct {
helper.ORMInterface
conn *sql.DB
}

func CreateJet() helper.ORMInterface {
return &Jet{}
}

func (jet *Jet) Name() string {
return "jet"
}

func (jet *Jet) Init() error {
var err error
jet.conn, err = sql.Open("pgx", helper.OrmSource)
if err != nil {
return err
}

return nil
}

func (jet *Jet) Close() error {
return jet.conn.Close()
}

func (jet *Jet) Insert(b *testing.B) {
m := NewModelJet()

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := Models.INSERT(Models.MutableColumns).MODEL(m).Exec(jet.conn)
if err != nil {
helper.SetError(b, jet.Name(), "Insert", err.Error())
}
}
}

func (jet *Jet) InsertMulti(b *testing.B) {
ms := make([]*model.Models, 0, 100)
for i := 0; i < 100; i++ {
ms = append(ms, NewModelJet())
}

b.ReportAllocs()
b.ResetTimer()

bulk := make([]*model.Models, len(ms))
for i, m := range ms {

Check failure on line 65 in bench/jet.go

View workflow job for this annotation

GitHub Actions / GoLint

[golangci] reported by reviewdog 🐶 S1001: should use copy(to, from) instead of a loop (gosimple) Raw Output: bench/jet.go:65:2: S1001: should use copy(to, from) instead of a loop (gosimple) for i, m := range ms { ^
bulk[i] = m
}

for i := 0; i < b.N; i++ {
_, err := Models.INSERT(Models.MutableColumns).MODELS(ms).Exec(jet.conn)
if err != nil {
helper.SetError(b, jet.Name(), "InsertMulti", err.Error())
}
}
}

func (jet *Jet) Update(b *testing.B) {
m, err := jet.create()
if err != nil {
helper.SetError(b, jet.Name(), "Update", err.Error())
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, err := Models.UPDATE(Models.MutableColumns).MODEL(m).WHERE(Models.ID.EQ(jetpg.Int32(m.ID))).Exec(jet.conn)
if err != nil {
helper.SetError(b, jet.Name(), "Update", err.Error())
}
}
}

func (jet *Jet) Read(b *testing.B) {
m, err := jet.create()
if err != nil {
helper.SetError(b, jet.Name(), "Read", err.Error())
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
var mout model.Models
err := Models.SELECT(Models.AllColumns).
WHERE(Models.ID.EQ(jetpg.Int32(m.ID))).
Query(jet.conn, &mout)
if err != nil {
helper.SetError(b, jet.Name(), "Read", err.Error())
}
}
}

func (jet *Jet) ReadSlice(b *testing.B) {
for i := 0; i < 100; i++ {
_, err := jet.create()
if err != nil {
helper.SetError(b, jet.Name(), "ReadSlice", err.Error())
}
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
models := make([]model.Models, 100)
err := Models.SELECT(Models.AllColumns).WHERE(Models.ID.GT(jetpg.Int32(0))).LIMIT(100).Query(jet.conn, &models)
if err != nil {
helper.SetError(b, jet.Name(), "ReadSlice", err.Error())
}
}
}

func (jet *Jet) create() (*model.Models, error) {
m := NewModelJet()

var created []model.Models
err := Models.INSERT(Models.MutableColumns).MODEL(m).RETURNING(Models.ID).Query(jet.conn, &created)
if err != nil {
return nil, err
}
m.ID = created[0].ID
return m, nil
}
3 changes: 3 additions & 0 deletions bench/jet/gen.go
@@ -0,0 +1,3 @@
package jet

//go:generate go run github.com/go-jet/jet/v2/cmd/jet -source=postgresql -user=postgres --password=postgres -dbname=test -host=localhost -port=5432 -path=./
19 changes: 19 additions & 0 deletions bench/jet/test/public/model/models.go

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

96 changes: 96 additions & 0 deletions bench/jet/test/public/table/models.go

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

14 changes: 14 additions & 0 deletions bench/jet/test/public/table/table_use_schema.go

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

5 changes: 5 additions & 0 deletions bench/jet/tool.go
@@ -0,0 +1,5 @@
//go:build tools

package jet

import _ "github.com/go-jet/jet/v2/cmd/jet"
14 changes: 14 additions & 0 deletions bench/models.go
Expand Up @@ -3,6 +3,7 @@ package bench
import (
"context"
"gitee.com/chunanyong/zorm"
jetmodel "github.com/efectn/go-orm-benchmarks/bench/jet/test/public/model"
r "github.com/efectn/go-orm-benchmarks/bench/reform"
models "github.com/efectn/go-orm-benchmarks/bench/sqlboiler"
)
Expand Down Expand Up @@ -227,3 +228,16 @@ func NewReformModel() *r.ReformModels {

return m
}

func NewModelJet() *jetmodel.Models {
m := new(jetmodel.Models)
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
}
5 changes: 5 additions & 0 deletions go.mod
Expand Up @@ -7,6 +7,7 @@ require (
gitee.com/chunanyong/zorm v1.6.9
github.com/astaxie/beego v1.12.3
github.com/friendsofgo/errors v0.9.2
github.com/go-jet/jet/v2 v2.10.1
github.com/go-pg/pg/v10 v10.11.1
github.com/go-rel/postgres v0.8.0
github.com/go-rel/rel v0.39.0
Expand Down Expand Up @@ -37,6 +38,7 @@ require (
github.com/agext/levenshtein v1.2.3 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fatih/color v1.15.0 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/go-openapi/inflect v0.19.0 // indirect
Expand Down Expand Up @@ -83,13 +85,15 @@ require (
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/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.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.3.1 // 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.5.1 // indirect
github.com/stretchr/testify v1.8.2 // 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 @@ -107,6 +111,7 @@ require (
golang.org/x/tools v0.11.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.2.0 // indirect
gorm.io/driver/mysql v1.5.1 // indirect
gorm.io/hints v1.1.2 // indirect
Expand Down

0 comments on commit 833e3d1

Please sign in to comment.