diff --git a/Benchmarks.md b/Benchmarks.md new file mode 100644 index 0000000..47345a6 --- /dev/null +++ b/Benchmarks.md @@ -0,0 +1,70 @@ +## Benchmark Comparison + +The results of the benchmark are good: +they show that ksql is in practical terms, +as fast as sqlx which was our goal from the start. + +To understand the benchmark below you must know +that all tests are performed using Postgres 12.1 and +that we are comparing the following tools: + +- ksql using the adapter that wraps database/sql +- ksql using the adapter that wraps pgx +- sql +- sqlx +- pgx (with pgxpool) +- gorm + +For each of these tools we are running 3 different queries: + +The `insert-one` query looks like: + +`INSERT INTO users (name, age) VALUES ($1, $2) RETURNING id` + +The `single-row` query looks like: + +`SELECT id, name, age FROM users OFFSET $1 LIMIT 1` + +The `multiple-rows` query looks like: + +`SELECT id, name, age FROM users OFFSET $1 LIMIT 10` + +Keep in mind that some of the tools tested actually build +the query internally so the actual query might differ a little +bit from the example ones above. + +Without further ado, here are the results: + +```bash +$ make bench TIME=5s +cd benchmarks && go test -bench=. -benchtime=5s +goos: linux +goarch: amd64 +pkg: github.com/vingarcia/ksql/benchmarks +cpu: Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz +BenchmarkInsert/ksql/sql-adapter/insert-one-12 7966 630421 ns/op +BenchmarkInsert/ksql/pgx-adapter/insert-one-12 10000 557143 ns/op +BenchmarkInsert/sql/insert-one-12 9296 627834 ns/op +BenchmarkInsert/sql/prep-statements/insert-one-12 10836 561999 ns/op +BenchmarkInsert/sqlx/insert-one-12 9686 638942 ns/op +BenchmarkInsert/pgxpool/insert-one-12 10000 567271 ns/op +BenchmarkInsert/gorm/insert-one-12 9163 669396 ns/op +BenchmarkQuery/ksql/sql-adapter/single-row-12 42124 149014 ns/op +BenchmarkQuery/ksql/sql-adapter/multiple-rows-12 38244 157941 ns/op +BenchmarkQuery/ksql/pgx-adapter/single-row-12 88578 70401 ns/op +BenchmarkQuery/ksql/pgx-adapter/multiple-rows-12 74156 81391 ns/op +BenchmarkQuery/sql/single-row-12 42818 142127 ns/op +BenchmarkQuery/sql/multiple-rows-12 38788 148733 ns/op +BenchmarkQuery/sql/prep-statements/single-row-12 85287 69135 ns/op +BenchmarkQuery/sql/prep-statements/multiple-rows-12 80311 73877 ns/op +BenchmarkQuery/sqlx/single-row-12 41606 146031 ns/op +BenchmarkQuery/sqlx/multiple-rows-12 39592 154469 ns/op +BenchmarkQuery/pgxpool/single-row-12 88638 66996 ns/op +BenchmarkQuery/pgxpool/multiple-rows-12 83715 71674 ns/op +BenchmarkQuery/gorm/single-row-12 80734 73582 ns/op +BenchmarkQuery/gorm/multiple-rows-12 63243 95192 ns/op +PASS +ok github.com/vingarcia/ksql/benchmarks 146.098s +Benchmark executed at: 2022-01-20 +Benchmark executed on commit: 8cd7a37da9c74f6f365665cd0c20d24843284421 +``` \ No newline at end of file