-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
312 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 GitHub Actions / GoLint
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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=./ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
//go:build tools | ||
|
||
package jet | ||
|
||
import _ "github.com/go-jet/jet/v2/cmd/jet" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.