A benchmarking shootout of various db/SQL utilities for Go

golang-db-sql-benchmark

A collection of benchmarks for popular Go database/SQL utilities

Libraries under test

database/sql SQL Execution Benchmarks:

  • BenchmarkPreparedStatementsNone - Runs simple queries without query arguments, so database/sql doesn't need to create a prepared statement
  • BenchmarkPreparedStatementsThrowaway - Runs queries with query arguments. database/sql must create and then throwaway a prepared statement each time
  • BenchmarkPreparedStatementsSingle - Runs queries with query arguments, but creates and reuses the a single prepared statement

Dbr/Sqlx/Gorp SQL Execution Benchmarks:

Each library under test has the same set of benchmarks, just replace Dbr in the examples with Sqlx or Gorp. Each one is run with varying number of rows, N.

  • BenchmarkDbrSelectIntsN - Select rows of integers into []int64's
  • BenchmarkDbrSelectAllN - Select rows into structs using no query arguments
  • BenchmarkDbrSelectAllWithArgsN - Select rows into structs using query arguments

Dbr/Squrrel SQL Building Benchamrks

Test building (but not executing) various SQL statements

  • BenchmarkBuilderDbrSimple - Simple SQL query with dbr
  • BenchmarkBuilderDbrComplex - Complex SQL query with dbr
  • BenchmarkBuilderSquirrelSimple - Simple SQL query with squirrel
  • BenchmarkBuilderSquirrelComplex - Complex SQL query with squirrel

Output

godep go test -bench=. -benchmem 2>/dev/null | column -t on @tyler-smith's 2.6 GHz i7 Macbook Pro:

BenchmarkPreparedStatementsNone       100000       23137     ns/op  612      B/op  20     allocs/op
BenchmarkPreparedStatementsThrowaway  20000        94086     ns/op  795      B/op  25     allocs/op
BenchmarkPreparedStatementsSingle     50000        33426     ns/op  652      B/op  23     allocs/op

BenchmarkDbrSelectInts1               100000       30098     ns/op  1198     B/op  22     allocs/op
BenchmarkDbrSelectInts100             20000        94477     ns/op  11645    B/op  426    allocs/op
BenchmarkDbrSelectInts1000            5000         627958    ns/op  100574   B/op  4041   allocs/op
BenchmarkDbrSelectInts10000           500          6207828   ns/op  1297929  B/op  40177  allocs/op
BenchmarkDbrSelectAll1                50000        35468     ns/op  1876     B/op  60     allocs/op
BenchmarkDbrSelectAll100              10000        157510    ns/op  29256    B/op  863    allocs/op
BenchmarkDbrSelectAll1000             2000         1436856   ns/op  272365   B/op  8078   allocs/op
BenchmarkDbrSelectAll10000            100          12927094  ns/op  2979829  B/op  80171  allocs/op
BenchmarkDbrSelectAllWithArgs1        50000        38959     ns/op  2590     B/op  72     allocs/op
BenchmarkDbrSelectAllWithArgs100      10000        162227    ns/op  29970    B/op  875    allocs/op
BenchmarkDbrSelectAllWithArgs1000     2000         1227154   ns/op  273765   B/op  8093   allocs/op
BenchmarkDbrSelectAllWithArgs10000    100          13342026  ns/op  3000164  B/op  80284  allocs/op

BenchmarkSqlxSelectInts1              20000        86128     ns/op  628      B/op  22     allocs/op
BenchmarkSqlxSelectInts100            10000        203886    ns/op  9480     B/op  426    allocs/op
BenchmarkSqlxSelectInts1000           2000         1289621   ns/op  83799    B/op  4038   allocs/op
BenchmarkSqlxSelectInts10000          100          15156243  ns/op  1134724  B/op  40139  allocs/op
BenchmarkSqlxSelectAll1               50000        32373     ns/op  959      B/op  25     allocs/op
BenchmarkSqlxSelectAll100             10000        177965    ns/op  28366    B/op  828    allocs/op
BenchmarkSqlxSelectAll1000            1000         1634705   ns/op  271352   B/op  8042   allocs/op
BenchmarkSqlxSelectAll10000           100          17483420  ns/op  2989883  B/op  80191  allocs/op
BenchmarkSqlxSelectAllWithArgs1       10000        140460    ns/op  1228     B/op  30     allocs/op
BenchmarkSqlxSelectAllWithArgs100     10000        250621    ns/op  23682    B/op  634    allocs/op
BenchmarkSqlxSelectAllWithArgs1000    2000         1548073   ns/op  229879   B/op  6049   allocs/op
BenchmarkSqlxSelectAllWithArgs10000   100          15441239  ns/op  2587009  B/op  60190  allocs/op

BenchmarkGorpSelectInts1              10000        134277    ns/op  432      B/op  15     allocs/op
BenchmarkGorpSelectAll1               50000        44086     ns/op  1983     B/op  75     allocs/op
BenchmarkGorpSelectAll100             10000        232527    ns/op  34258    B/op  978    allocs/op
BenchmarkGorpSelectAll1000            1000         1563675   ns/op  321846   B/op  9100   allocs/op
BenchmarkGorpSelectAll10000           100          16451807  ns/op  3472508  B/op  90250  allocs/op
BenchmarkGorpSelectAllWithArgs1       10000        131738    ns/op  2306     B/op  80     allocs/op
BenchmarkGorpSelectAllWithArgs100     10000        265323    ns/op  29948    B/op  785    allocs/op
BenchmarkGorpSelectAllWithArgs1000    2000         1423747   ns/op  279838   B/op  7103   allocs/op
BenchmarkGorpSelectAllWithArgs10000   100          14538568  ns/op  3072519  B/op  70263  allocs/op

BenchmarkBuilderDbrSimple             1000000      1699      ns/op  866      B/op  13     allocs/op
BenchmarkBuilderDbrComplex            500000       6193      ns/op  2190     B/op  37     allocs/op

BenchmarkBuilderSquirrelSimple        200000       8981      ns/op  2780     B/op  51     allocs/op
BenchmarkBuilderSquirrelComplex       50000        44721     ns/op  11707    B/op  259    allocs/op

Run yourself

  • Use the godep tool or manually install all libraries under test
  • Create db: mysql -e "create database golang_sql_benchmarks;"
  • Create schema: mysql golang_sql_benchmarks < structure.sql
  • Run: godep go test -bench=. -benchmem
  • You can set the MySQL DSN to use by setting the GOLANG_SQL_BENCHMARKS_DSN env var (defaults to root@unix(/var/run/mysqld/mysqld.sock)/golang_sql_benchmarks)
Similar Resources

Fast cross-platform HTTP benchmarking tool written in Go

bombardier bombardier is a HTTP(S) benchmarking tool. It is written in Go programming language and uses excellent fasthttp instead of Go's default htt

Jan 2, 2023

Application for HTTP benchmarking via different rules and configs

Application for HTTP benchmarking via different rules and configs

Go Benchmark App The efficiency and speed of application - our goal and the basic idea. Application for HTTP-benchmarking via different rules and conf

Dec 24, 2022

HTTP Load Testing And Benchmarking Tool

GBench HTTP Load Testing And Benchmarking Tool inspired by Apache Benchmark and Siege. Requirements You need Golang installed and ready on your system

Jan 2, 2020

HTTP/HTTPS load testing and benchmarking tool

Introduction I wrote that code because: (the obvious reason::I love to write code in Go) We are working so hard to optimize our servers - why shouldn'

Dec 5, 2022

Stress testing and benchmarking tool for the NEAR EVM

evm-bully --- stress testing and benchmarking tool for the NEAR EVM

May 30, 2022

Fast cross-platform HTTP benchmarking tool written in Go

bombardier bombardier is a HTTP(S) benchmarking tool. It is written in Go programming language and uses excellent fasthttp instead of Go's default htt

Dec 31, 2022

go-wrk - a HTTP benchmarking tool based in spirit on the excellent wrk tool (https://github.com/wg/wrk)

go-wrk - an HTTP benchmarking tool go-wrk is a modern HTTP benchmarking tool capable of generating significant load when run on a single multi-core CP

Jan 5, 2023

a benchmarking&stressing tool that can send raw HTTP requests

reqstress reqstress is a benchmarking&stressing tool that can send raw HTTP requests. It's written in Go and uses fasthttp library instead of Go's def

Dec 18, 2022

Plow is a high-performance HTTP benchmarking tool with real-time web UI and terminal displaying

Plow is a high-performance HTTP benchmarking tool with real-time web UI and terminal displaying

Plow is a HTTP(S) benchmarking tool, written in Golang. It uses excellent fasthttp instead of Go's default net/http due to its lightning fast performance.

Jan 9, 2023

Benchmarking hash functions in Go

Experiment: Benchmarks of Hash Functions in Go This repository contains a small experiment of mine, trying out different hash functions and comparing

Jun 22, 2022

Toy program for benchmarking safe and unsafe ways of saving a file

save-a-file benchmarks the many strategies an editor could use to save a file. Example output on a SSD: ext4: $ ./save-a-file ~/tmp/foo 29.195ยตs per s

Jan 4, 2023

Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and GraphQL.

Go GraphQL Simple vanilla Go CRUD application with mongoDB database with its mflix dataset that I use for my thesis about benchmarking REST API and Gr

Oct 15, 2021

Frisbee is a Kubernetes-native platform for exploring, testing, and benchmarking distributed applications.

Frisbee is a Kubernetes-native platform for exploring, testing, and benchmarking distributed applications.

Why Frisbee ? Frisbee is a next generation platform designed to unify chaos testing and perfomance benchmarking. We address the key pain points develo

Dec 14, 2022

Performance-focused HTTP benchmarking tool written in Go

๐Ÿ’ฅ gocannon - HTTP benchmarking tool Gocannon is a lightweight HTTP benchmarking tool, intended to measure changes in backend application performance

Dec 22, 2022

Make TCP connection storm between server and client for benchmarking network stuff

Make TCP connection storm between server and client for benchmarking network stuff

Nov 14, 2021

DNS benchmarking utility For Golang

DNSBench โ€” DNS benchmarking utility Installation go get -u github.com/leonklingele/dnsbench/... dnsbench -help Run benchmark dnsbench -domains google.

Apr 30, 2022

Benchmarking deferent Fibonacci functions and algorithms with running unit test

GoFibonacciBench Benchmarking deferent Fibonacci functions and algorithms with running unit test ... Introduction: Fibonacci numbers are special kinds

Feb 27, 2022

Benchmore - A package allows you to report On-CPU Time in addition to the wall time measured by Go's builtin benchmarking framework

benchmore This package allows you to report On-CPU Time in addition to the wall

Feb 9, 2022

Command line tool to generate idiomatic Go code for SQL databases supporting PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server

About xo xo is a command-line tool to generate Go code based on a database schema or a custom query. xo works by using database metadata and SQL intro

Jan 8, 2023
Performance-focused HTTP benchmarking tool written in Go

?? gocannon - HTTP benchmarking tool Gocannon is a lightweight HTTP benchmarking tool, intended to measure changes in backend application performance

Dec 22, 2022
Compare various Image resize algorithms for the Go language

speedtest-resize Compare various Image resize algorithms for the Go language I am writing a web gallery called gonagall in Go (https://github.com/fawi

Dec 8, 2022
Convert various benchmarking formats to benchfmt

benchfmt-convert This repo contains tools for converting various formats to benchfmt for use with benchstat. Most useful is github.com/prattmic/benchf

Sep 17, 2021
The Cloud Posse Terraform Provider for various utilities (E.g. deep merging)
The Cloud Posse Terraform Provider for various utilities (E.g. deep merging)

terraform-provider-utils Terraform provider to add additional missing functionality to Terraform This project is part of our comprehensive "SweetOps"

Jan 7, 2023
This repository provides various utilities to help you build your NFT collection!

Attention! A powerful computer may be required! About This repository provides various utilities to help you build your NFT collection: Generate image

Nov 4, 2022
Elektra-Auto-Checkout - Utilities to assist in checkout automation of various commercial and retail sites

Elektra About This Project Elektra is designed to automate the process of invent

Dec 5, 2022
This package includes various utilities and extensions for your Go code.

Go utilities This package includes various utilities and extensions for your Go code. Inspired by lodash Install go get github.com/murat/go-utils@mast

May 11, 2022
CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. Can output to various formats.
CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. Can output to various formats.

trdsql CLI tool that can execute SQL queries on CSV, LTSV, JSON and TBLN. It is a tool like q, textql and others. The difference from these tools is t

Jan 1, 2023
๐Ÿ‹๏ธ dbbench is a simple database benchmarking tool which supports several databases and own scripts

dbbench Table of Contents Description Example Installation Supported Databases Usage Custom Scripts Troubeshooting Development Acknowledgements Descri

Dec 30, 2022
Small TCP benchmarking tool in Go-lang

Simple TCP benchmark tool in Go =============================== This package provides simple command line tool to benchmark number of concurrent TCP

Aug 16, 2021