Skip to content

Commit 5ad9c11

Browse files
author
Miguel Molina
authored
Merge pull request #112 from erizocosmico/feature/benchmarks
benchmarks: preliminary benchmarks with GORM and Kallax
2 parents 1d78553 + 1349ada commit 5ad9c11

File tree

6 files changed

+1496
-1
lines changed

6 files changed

+1496
-1
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ test:
88
tail -n +2 $(COVERAGE_PROFILE) >> $(COVERAGE_REPORT); \
99
rm $(COVERAGE_PROFILE); \
1010
fi; \
11-
for dir in `find . -name "*.go" | grep -o '.*/' | sort -u | grep -v './tests/' | grep -v './fixtures/'`; do \
11+
for dir in `find . -name "*.go" | grep -o '.*/' | sort -u | grep -v './tests/' | grep -v './fixtures/' | grep -v './benchmarks/'`; do \
1212
go test $$dir -coverprofile=$(COVERAGE_PROFILE) -covermode=$(COVERAGE_MODE); \
1313
if [ $$? != 0 ]; then \
1414
exit 2; \

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Support for arrays of all basic Go types and all JSON and arrays operators is pr
3535
* [Query with relationships](#query-with-relationships)
3636
* [Querying JSON](#querying-json)
3737
* [Transactions](#transactions)
38+
* [Benchmarks](#benchmarks)
3839
* [Contributing](#contributing)
3940

4041
## Installation
@@ -600,6 +601,40 @@ store.Transaction(func(s *UserStore) error {
600601
* `time.Time` and `url.URL` need to be used as is. That is, you can not use a type `Foo` being `type Foo time.Time`. `time.Time` and `url.URL` are types that are treated in a special way, if you do that, it would be the same as saying `type Foo struct { ... }` and kallax would no longer be able to identify the correct type.
601602
* Multidimensional arrays or slices are **not supported** except inside a JSON field.
602603

604+
## Benchmarks
605+
606+
Here are some benchmarks against [GORM](https://github.com/jinzhu/gorm) and `database/sql`, which is one of the most popular ORMs for Go. In the future we might add benchmarks for some more complex cases and other available ORMs.
607+
608+
```
609+
BenchmarkKallaxInsertWithRelationships-4 300 4767574 ns/op 19130 B/op 441 allocs/op
610+
BenchmarkRawSQLInsertWithRelationships-4 300 4467652 ns/op 3997 B/op 114 allocs/op
611+
BenchmarkGORMInsertWithRelationships-4 300 4813566 ns/op 34550 B/op 597 allocs/op
612+
613+
BenchmarkKallaxInsert-4 500 3650913 ns/op 3569 B/op 85 allocs/op
614+
BenchmarkRawSQLInsert-4 500 3530908 ns/op 901 B/op 24 allocs/op
615+
BenchmarkGORMInsert-4 300 3716373 ns/op 4558 B/op 104 allocs/op
616+
617+
BenchmarkKallaxQueryRelationships/query-4 1000 1535928 ns/op 59335 B/op 1557 allocs/op
618+
BenchmarkRawSQLQueryRelationships/query-4 30 44225743 ns/op 201288 B/op 6021 allocs/op
619+
BenchmarkGORMQueryRelationships/query-4 300 4012112 ns/op 1068887 B/op 20827 allocs/op
620+
621+
BenchmarkKallaxQuery/query-4 3000 433453 ns/op 50697 B/op 1893 allocs/op
622+
BenchmarkRawSQLQuery/query-4 5000 368947 ns/op 37392 B/op 1522 allocs/op
623+
BenchmarkGORMQuery/query-4 2000 1311137 ns/op 427308 B/op 7065 allocs/op
624+
625+
PASS
626+
ok gopkg.in/src-d/go-kallax.v1/benchmarks 31.313s
627+
```
628+
629+
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.
630+
631+
Source code of the benchmarks can be found on the [benchmarks](https://github.com/src-d/go-kallax/tree/master/benchmarks) folder.
632+
633+
**Notes:**
634+
635+
* Benchmarks were run on a 2015 MacBook Pro with i5 and 8GB of RAM and 128GB SSD hard drive running fedora 25.
636+
* 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.
637+
603638
## Contributing
604639

605640
### Reporting bugs

0 commit comments

Comments
 (0)