0
0
mirror of https://gitlab.com/cznic/sqlite.git synced 2025-05-02 23:11:33 +00:00
Files
go-sqlite/cgo_test.go
Jan Mercl 1c17040813 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
2021-01-07 15:07:26 +01:00

127 lines
2.1 KiB
Go

// Copyright 2017 The Sqlite Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//+build cgo,cgobench
package sqlite // import "modernc.org/sqlite"
import (
"database/sql"
"fmt"
"os"
"path/filepath"
"testing"
_ "github.com/mattn/go-sqlite3"
)
const gcoDriver = "sqlite3"
var drivers = []string{
driverName,
gcoDriver,
}
var inMemory = []bool{
true,
false,
}
func makename(inMemory bool, driver string, e int) string {
name := driver
if inMemory {
name += "InMemory"
} else {
name += "OnDisk"
}
return fmt.Sprintf("%s1e%d", name, e)
}
func reading1Memory(b *testing.B, drivername, file string, n int) {
os.Remove(file)
db, err := sql.Open(drivername, file)
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 < n; i++ {
if _, err := s.Exec(int64(i)); err != nil {
b.Fatal(err)
}
}
if _, err := db.Exec("commit"); err != nil {
b.Fatal(err)
}
dst := 0
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(r.Err())
}
err = r.Scan(&dst)
if err != nil {
b.Fatal(err)
}
}
b.StopTimer()
r.Close()
}
b.StopTimer()
if *oRecsPerSec {
b.SetBytes(1e6 * int64(n))
}
}
func BenchmarkReading1(b *testing.B) {
dir := b.TempDir()
for _, memory := range inMemory {
filename := "file::memory:"
if !memory {
filename = filepath.Join(dir, "test.db")
}
for _, driver := range drivers {
for i, n := range []int{1e1, 1e2, 1e3, 1e4, 1e5, 1e6} {
b.Run(makename(memory, driver, i+1), func(b *testing.B) {
reading1Memory(b, driver, filename, n)
if !memory {
err := os.Remove(filename)
if err != nil {
b.Fatal(err)
}
}
})
}
}
}
}