https://github.com/cvilsmeier/go-sqlite-bench Skip to content Toggle navigation Sign in * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Resources + Learning Pathways + White papers, Ebooks, Webinars + Customer Stories + Partners * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing Search or jump to... Search code, repositories, users, issues, pull requests... Search [ ] Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. [ ] [ ] Include my email address so I can be contacted Cancel Submit feedback Saved searches Use saved searches to filter your results more quickly Name [ ] Query [ ] To see all available qualifiers, see our documentation. Cancel Create saved search Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} cvilsmeier / go-sqlite-bench Public * Notifications * Fork 1 * Star 71 Benchmarks for Golang SQLite Drivers License Unlicense license 71 stars 1 fork Activity Star Notifications * Code * Issues 1 * Pull requests 0 * Actions * Projects 0 * Security * Insights Additional navigation options * Code * Issues * Pull requests * Actions * Projects * Security * Insights cvilsmeier/go-sqlite-bench This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 1 branch 0 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/c] Use Git or checkout with SVN using the web URL. [gh repo clone cvilsm] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @cvilsmeier cvilsmeier sponsored by Monibot ... f4e8f2b Dec 13, 2023 sponsored by Monibot f4e8f2b Git stats * 17 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time app explicit journal mode and synchronous December 9, 2023 18:46 cmd add ncruces driver December 9, 2023 19:52 results add ncruces driver December 9, 2023 19:52 .gitignore Initial commit June 14, 2020 19:26 LICENSE Initial commit June 14, 2020 19:26 README.md sponsored by Monibot December 13, 2023 11:52 all.sh update libs December 9, 2023 16:46 go.mod add ncruces driver December 9, 2023 19:52 go.sum add ncruces driver December 9, 2023 19:52 View code [ ] Benchmarks for Golang SQLite Drivers Database Schema Benchmarks Simple Complex Many Large Concurrent Summary README.md Benchmarks for Golang SQLite Drivers This work is sponsored by Monibot - Easy Server and Application Monitoring. Try out Monibot at https://monibot.io. It's free. For benchmarks I used the following libraries: * craw, crawshaw.io/sqlite, a CGO-based solution. This is not a database/sql driver. * mattn, github.com/mattn/go-sqlite3, a CGO-based solution. This library is (still) the de-facto standard and widely used. * modernc, modernc.org/sqlite, a pure Go solution. This is a newer library, based on the SQLite C code re-written in Go. * ncruces, github.com/ncruces/go-sqlite3, a pure Go solution based on WASM (?). * sqinn, github.com/cvilsmeier/sqinn-go, a solution without CGO. It uses github.com/cvilsmeier/sqinn to access SQLite database files. * zombie, github.com/zombiezen/go-sqlite, a rewrite of the crawshaw driver, using the modernc libraries. This is not a database/sql driver. The test setup is as follows: * OS: Debian/GNU Linux amd64 version 12.3 * CPU: 11th Gen Intel(R) Core(TM) i7-1165G7 @ 2.80GHz, 4 physical cores, 8 logical cores * RAM: 16GB * Disk: 1TB NVME SSD * go version go1.21.5 linux/amd64 The benchmark was run on 2023-12-09, with then-current library versions. See go.mod for library versions. Each test was run once for warmup. The second run was then recorded. A general note on benchmarks: Do not trust benchmarks, write your own. This specific benchmark is modelled after my very own database usage scenarios. Your scenarios may be totally different. Database Schema The test database consist of the following tables and indizes: PRAGMA journal_mode=DELETE; PRAGMA synchronous=FULL; PRAGMA foreign_keys=1; PRAGMA busy_timeout=5000; CREATE TABLE users ( id INTEGER PRIMARY KEY NOT NULL, created INTEGER NOT NULL, email TEXT NOT NULL, active INTEGER NOT NULL); CREATE INDEX users_created ON users(created); CREATE TABLE articles ( id INTEGER PRIMARY KEY NOT NULL, created INTEGER NOT NULL, userId INTEGER NOT NULL REFERENCES users(id), text TEXT NOT NULL); CREATE INDEX articles_created ON articles(created); CREATE INDEX articles_userId ON articles(userId); CREATE TABLE comments ( id INTEGER PRIMARY KEY NOT NULL, created INTEGER NOT NULL, articleId INTEGER NOT NULL REFERENCES articles(id), text TEXT NOT NULL); CREATE INDEX comments_created ON comments(created); CREATE INDEX comments_articleId ON comments(articleId); Benchmarks Result times are measured in milliseconds. Lower numbers indicate better performance. Simple Insert 1 million user rows in one database transaction. Then query all users once. [simple] insert query ------------------------------------- craw 1234 ms 608 ms mattn 1537 ms 1267 ms modernc 5557 ms 1379 ms ncruces 10073 ms 6080 ms sqinn 883 ms 641 ms zombie 1862 ms 325 ms Complex Insert 200 users in one database transaction. Then insert 20000 articles (100 articles for each user) in another transaction. Then insert 400000 comments (20 comments for each article) in another transaction. Then query all users, articles and comments in one big JOIN statement. [complex] insert query ------------------------------------- craw 729 ms 667 ms mattn 911 ms 1387 ms modernc 3211 ms 1633 ms ncruces 5159 ms 5380 ms sqinn 574 ms 709 ms zombie 1400 ms 507 ms Many Insert N users in one database transaction. Then query all users 1000 times. This benchmark is used to simluate a read-heavy use case. [many] query/N=10 query/N=100 query/N=1000 -------------------------------------------------------- craw 14 ms 65 ms 520 ms mattn 30 ms 130 ms 1143 ms modernc 35 ms 135 ms 1180 ms ncruces 185 ms 829 ms 7230 ms sqinn 25 ms 83 ms 619 ms zombie 17 ms 36 ms 225 ms Large Insert 10000 users with N bytes of row content. Then query all users. This benchmark is used to simluate reading of large (gigabytes) databases. [large] query/N=50000 query/N=100000 query/N=200000 --------------------------------------------------- craw 197 ms 346 ms 624 ms mattn 168 ms 290 ms 591 ms modernc 276 ms 514 ms 888 ms ncruces 244 ms 391 ms 789 ms sqinn 519 ms 1085 ms 2264 ms zombie 552 ms 1071 ms 2198 ms Concurrent Insert one million users. Then have N goroutines query all users. This benchmark is used to simulate concurrent reads. [concurrent] query/N=2 query/N=4 query/N=8 --------------------------------------- craw 692 ms 1100 ms 1873 ms mattn 1516 ms 1840 ms 3483 ms modernc 2889 ms 7144 ms 18674 ms ncruces 8268 ms 12710 ms 25792 ms sqinn 854 ms 1411 ms 2460 ms zombie 367 ms 646 ms 1140 ms Summary * We cannot declare a winner, it all depends on the use case. * Crawshaw and Zombiezen are pretty fast. * Mattn, although the de-facto standard, is not the best overall solution. * SQLite without CGO is possible. This work is sponsored by Monibot - Easy Server and Application Monitoring. Try out Monibot at https://monibot.io. It's free. About Benchmarks for Golang SQLite Drivers Topics golang sqlite Resources Readme License Unlicense license Activity Stars 71 stars Watchers 2 watching Forks 1 fork Report repository Releases No releases published Packages 0 No packages published Languages * Go 99.9% * Shell 0.1% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact * You can't perform that action at this time.