Skip to content

Commit cf0ccd9

Browse files
aarondlRoberto Santalla
authored andcommitted
Fix the sqlboiler benchmark (#269)
* Fix the sqlboiler benchmark Did not update the readme numbers since I don't have the same hardware and don't have the other ORMs set up properly. * Update readme. - Add disclaimer about out of date benchmark - Replace out of date benchmark with XXX - Tune wording around sqlboiler's performance
1 parent 6e31900 commit cf0ccd9

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,7 @@ BenchmarkKallaxUpdate-4 300 4179176 ns/op 65
829829
BenchmarkKallaxUpdateWithRelationships-4 200 5662703 ns/op 6642 B/op 175 allocs/op
830830
831831
BenchmarkKallaxInsertWithRelationships-4 200 5648433 ns/op 10221 B/op 218 allocs/op
832-
BenchmarkSQLBoilerInsertWithRelationships-4 100 17543073 ns/op 5898 B/op 185 allocs/op
832+
BenchmarkSQLBoilerInsertWithRelationships-4 XXX XXXXXXX ns/op XXXX B/op XXX allocs/op
833833
BenchmarkRawSQLInsertWithRelationships-4 200 5427503 ns/op 4516 B/op 127 allocs/op
834834
BenchmarkGORMInsertWithRelationships-4 200 6196277 ns/op 35080 B/op 610 allocs/op
835835
@@ -852,12 +852,13 @@ PASS
852852
ok gopkg.in/src-d/go-kallax.v1/benchmarks 44.899s
853853
```
854854

855-
As we can see on the benchmark, the performance loss is not very much compared to raw `database/sql`, while GORMs performance loss is very big and the memory consumption is way higher. SQLBoiler, on the other hand, has a lower memory footprint than kallax (in some cases), but a bigger performance loss (though not very significant in most cases), except for queries with relationships (that is a regression, though, and should be improved in the future).
855+
As we can see on the benchmark, the performance loss is not very much compared to raw `database/sql`, while GORMs performance loss is very big and the memory consumption is way higher. SQLBoiler, on the other hand, has a lower memory footprint than kallax (in some cases), but a bigger performance loss (though not very significant), except for queries with relationships (that is a regression, though, and should be improved in the future).
856856

857857
Source code of the benchmarks can be found on the [benchmarks](https://github.com/src-d/go-kallax/tree/master/benchmarks) folder.
858858

859859
**Notes:**
860860

861+
* Benchmark runs are out of date as of 2018-05-28 (result of PR #269), some results are pending a re-run and will be updated soon.
861862
* Benchmarks were run on a 2015 MacBook Pro with i5 and 8GB of RAM and 128GB SSD hard drive running fedora 25.
862863
* Benchmark of `database/sql` for querying with relationships is implemented with a very naive 1+n solution. That's why the result is that bad.
863864

benchmarks/bench_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,22 @@ func BenchmarkSQLBoilerInsertWithRelationships(b *testing.B) {
140140
defer teardownDB(b, db)
141141

142142
for i := 0; i < b.N; i++ {
143+
tx, _ := db.Begin()
143144
person := &models.Person{Name: null.StringFrom("Dolan")}
144-
if err := person.Insert(db); err != nil {
145+
if err := person.Insert(tx); err != nil {
145146
b.Fatalf("error inserting: %s", err)
146147
}
147148

148-
err := person.SetPets(db, true, []*models.Pet{
149+
err := person.SetPets(tx, true, []*models.Pet{
149150
{Name: null.StringFrom("Garfield"), Kind: null.StringFrom("cat")},
150151
{Name: null.StringFrom("Oddie"), Kind: null.StringFrom("dog")},
151152
{Name: null.StringFrom("Reptar"), Kind: null.StringFrom("fish")},
152153
}...)
153154
if err != nil {
154155
b.Fatalf("error inserting relationships: %s", err)
155156
}
157+
158+
tx.Commit()
156159
}
157160
}
158161

@@ -483,7 +486,7 @@ func BenchmarkGORMQuery(b *testing.B) {
483486
var persons []*GORMPerson
484487
db := store.Find(&persons)
485488
if db.Error != nil {
486-
b.Fatalf("error retrieving persons:", db.Error)
489+
b.Fatal("error retrieving persons:", db.Error)
487490
}
488491
}
489492
})

0 commit comments

Comments
 (0)