mirror of
https://github.com/glebarez/go-sqlite.git
synced 2025-10-04 07:26:28 +08:00
Make benchmarks try different table sizes
jnml@3900x:~/src/modernc.org/sqlite$ go test -tags cgobench -run @ -bench . -recs_per_sec_as_mbps |& tee log test binary compiled for linux/amd64 goos: linux goarch: amd64 pkg: modernc.org/sqlite BenchmarkInsertMemory/1e1-24 17526 69420 ns/op 144051.54 MB/s 2242 B/op 70 allocs/op BenchmarkInsertMemory/1e2-24 1861 713302 ns/op 140192.98 MB/s 22427 B/op 700 allocs/op BenchmarkInsertMemory/1e3-24 168 6949300 ns/op 143899.38 MB/s 230079 B/op 7744 allocs/op BenchmarkInsertMemory/1e4-24 16 66353146 ns/op 150708.76 MB/s 2320327 B/op 79748 allocs/op BenchmarkInsertMemory/1e5-24 2 2125566987 ns/op 47046.27 MB/s 23211064 B/op 799876 allocs/op BenchmarkInsertMemory/1e6-24 1 32409599180 ns/op 30855.06 MB/s 232210448 B/op 8001572 allocs/op BenchmarkNextMemory/1e1-24 181816 6783 ns/op 1474180.21 MB/s 16 B/op 1 allocs/op BenchmarkNextMemory/1e2-24 22436 52581 ns/op 1901822.13 MB/s 16 B/op 1 allocs/op BenchmarkNextMemory/1e3-24 2810 461729 ns/op 2165773.65 MB/s 12432 B/op 1645 allocs/op BenchmarkNextMemory/1e4-24 264 4671249 ns/op 2140755.03 MB/s 156432 B/op 19645 allocs/op BenchmarkNextMemory/1e5-24 2 552415982 ns/op 181023.00 MB/s 1596432 B/op 199645 allocs/op BenchmarkNextMemory/1e6-24 1 5283792426 ns/op 189258.00 MB/s 15996480 B/op 1999645 allocs/op BenchmarkReading1/sqliteInMemory1e1-24 154976 6895 ns/op 1450348.96 MB/s 16 B/op 1 allocs/op BenchmarkReading1/sqliteInMemory1e2-24 22861 52974 ns/op 1887724.10 MB/s 16 B/op 1 allocs/op BenchmarkReading1/sqliteInMemory1e3-24 2499 449004 ns/op 2227153.62 MB/s 12432 B/op 1645 allocs/op BenchmarkReading1/sqliteInMemory1e4-24 264 4504266 ns/op 2220117.55 MB/s 156432 B/op 19645 allocs/op BenchmarkReading1/sqliteInMemory1e5-24 2 543267468 ns/op 184071.39 MB/s 1596432 B/op 199645 allocs/op BenchmarkReading1/sqliteInMemory1e6-24 1 5504469406 ns/op 181670.55 MB/s 15996464 B/op 1999645 allocs/op BenchmarkReading1/sqlite3InMemory1e1-24 165736 7426 ns/op 1346699.36 MB/s 320 B/op 37 allocs/op BenchmarkReading1/sqlite3InMemory1e2-24 20946 55017 ns/op 1817631.77 MB/s 2480 B/op 307 allocs/op BenchmarkReading1/sqlite3InMemory1e3-24 1741 619309 ns/op 1614701.91 MB/s 37232 B/op 4651 allocs/op BenchmarkReading1/sqlite3InMemory1e4-24 200 5970890 ns/op 1674792.32 MB/s 397235 B/op 49651 allocs/op BenchmarkReading1/sqlite3InMemory1e5-24 19 61240730 ns/op 1632900.20 MB/s 3997259 B/op 499651 allocs/op BenchmarkReading1/sqlite3InMemory1e6-24 2 620411424 ns/op 1611833.63 MB/s 39997508 B/op 4999652 allocs/op BenchmarkReading1/sqliteOnDisk1e1-24 179678 7028 ns/op 1422927.68 MB/s 16 B/op 1 allocs/op BenchmarkReading1/sqliteOnDisk1e2-24 25140 47970 ns/op 2084640.49 MB/s 16 B/op 1 allocs/op BenchmarkReading1/sqliteOnDisk1e3-24 2340 442164 ns/op 2261602.38 MB/s 12432 B/op 1645 allocs/op BenchmarkReading1/sqliteOnDisk1e4-24 266 4515133 ns/op 2214773.96 MB/s 156432 B/op 19645 allocs/op BenchmarkReading1/sqliteOnDisk1e5-24 3 446614930 ns/op 223906.53 MB/s 1596437 B/op 199645 allocs/op BenchmarkReading1/sqliteOnDisk1e6-24 1 4326258166 ns/op 231146.63 MB/s 15996464 B/op 1999645 allocs/op BenchmarkReading1/sqlite3OnDisk1e1-24 119437 9782 ns/op 1022315.11 MB/s 320 B/op 37 allocs/op BenchmarkReading1/sqlite3OnDisk1e2-24 20011 58941 ns/op 1696624.22 MB/s 2480 B/op 307 allocs/op BenchmarkReading1/sqlite3OnDisk1e3-24 1981 605212 ns/op 1652313.10 MB/s 37232 B/op 4651 allocs/op BenchmarkReading1/sqlite3OnDisk1e4-24 195 6269972 ns/op 1594903.42 MB/s 397234 B/op 49651 allocs/op BenchmarkReading1/sqlite3OnDisk1e5-24 18 62079585 ns/op 1610835.51 MB/s 3997248 B/op 499651 allocs/op BenchmarkReading1/sqlite3OnDisk1e6-24 2 612785354 ns/op 1631892.79 MB/s 39997520 B/op 4999652 allocs/op PASS ok modernc.org/sqlite 280.633s jnml@3900x:~/src/modernc.org/sqlite$ ok
This commit is contained in:
143
all_test.go
143
all_test.go
@@ -248,7 +248,58 @@ func TestBlob(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func benchmarkInsertMemory(b *testing.B, n int) {
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
}()
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
if _, err := db.Exec(`
|
||||
drop table if exists t;
|
||||
create table t(i int);
|
||||
begin;
|
||||
`); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := db.Prepare("insert into t values(?)")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
for i := 0; i < n; i++ {
|
||||
if _, err := s.Exec(int64(i)); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if _, err := db.Exec(`commit;`); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
if *oRecsPerSec {
|
||||
b.SetBytes(1e6 * int64(n))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkInsertMemory(b *testing.B) {
|
||||
for i, n := range []int{1e1, 1e2, 1e3, 1e4, 1e5, 1e6} {
|
||||
b.Run(fmt.Sprintf("1e%d", i+1), func(b *testing.B) { benchmarkInsertMemory(b, n) })
|
||||
}
|
||||
}
|
||||
|
||||
var staticInt int
|
||||
|
||||
func benchmarkNextMemory(b *testing.B, n int) {
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
@@ -259,9 +310,9 @@ func BenchmarkInsertMemory(b *testing.B) {
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
create table t(i int);
|
||||
begin;
|
||||
`); err != nil {
|
||||
create table t(i int);
|
||||
begin;
|
||||
`); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -270,70 +321,48 @@ func BenchmarkInsertMemory(b *testing.B) {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for i := 0; i < n; i++ {
|
||||
if _, err := s.Exec(int64(i)); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if *oRecsPerSec {
|
||||
b.SetBytes(1e6)
|
||||
}
|
||||
if _, err := db.Exec(`commit;`); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
b.StopTimer()
|
||||
r, err := db.Query("select * from t")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
b.StartTimer()
|
||||
for i := 0; i < n; i++ {
|
||||
if !r.Next() {
|
||||
b.Fatal(err)
|
||||
}
|
||||
if err := r.Scan(&staticInt); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if err := r.Err(); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
r.Close()
|
||||
}
|
||||
if *oRecsPerSec {
|
||||
b.SetBytes(1e6 * int64(n))
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkNextMemory(b *testing.B) {
|
||||
db, err := sql.Open(driverName, "file::memory:")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
defer func() {
|
||||
db.Close()
|
||||
}()
|
||||
|
||||
if _, err := db.Exec(`
|
||||
create table t(i int);
|
||||
begin;
|
||||
`); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
s, err := db.Prepare("insert into t values(?)")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
defer s.Close()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := s.Exec(int64(i)); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
if _, err := db.Exec("commit"); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
r, err := db.Query("select * from t")
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
|
||||
defer r.Close()
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
if !r.Next() {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
b.StopTimer()
|
||||
if *oRecsPerSec {
|
||||
b.SetBytes(1e6)
|
||||
for i, n := range []int{1e1, 1e2, 1e3, 1e4, 1e5, 1e6} {
|
||||
b.Run(fmt.Sprintf("1e%d", i+1), func(b *testing.B) { benchmarkNextMemory(b, n) })
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user