MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / BenchmarkCovenantSQLDriver

Function BenchmarkCovenantSQLDriver

client/clientbench_test.go:41–116  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

39var FJ = filepath.Join
40
41func BenchmarkCovenantSQLDriver(b *testing.B) {
42 var err error
43 log.SetLevel(log.DebugLevel)
44 err = os.Chdir(testWorkingDir)
45 if err != nil {
46 log.WithError(err).Error("change working dir failed")
47 return
48 }
49
50 once.Do(func() {
51 log.Debug("benchmarking")
52 err = Init(FJ(testWorkingDir, "./node_c/config.yaml"), []byte(""))
53 if err != nil {
54 b.Fatal(err)
55 }
56 })
57
58 // wait for chain service
59 var ctx1, cancel1 = context.WithTimeout(context.Background(), 1*time.Minute)
60 defer cancel1()
61 err = test.WaitBPChainService(ctx1, 3*time.Second)
62 if err != nil {
63 b.Fatalf("wait for chain service failed: %v", err)
64 }
65
66 // create
67 meta := ResourceMeta{}
68 meta.Node = 3
69 _, dsn, err := Create(meta)
70 if err != nil {
71 b.Fatal(err)
72 }
73
74 log.WithField("dsn", dsn).Info("created database")
75
76 db, err := sql.Open("covenantsql", dsn)
77 if err != nil {
78 b.Fatal(err)
79 }
80 _, err = db.Exec("CREATE TABLE test (test int)")
81 if err != nil {
82 b.Fatal(err)
83 }
84
85 b.Run("benchmark insert", func(b *testing.B) {
86 b.ResetTimer()
87 for i := 0; i < b.N; i++ {
88 _, err = db.Exec("INSERT INTO test VALUES(?)", i)
89 if err != nil {
90 b.Fatal(err)
91 }
92 }
93 })
94
95 b.Run("benchmark select", func(b *testing.B) {
96 b.ResetTimer()
97 for i := 0; i < b.N; i++ {
98 row := db.QueryRow("SELECT * FROM test LIMIT 1")

Callers

nothing calls this directly

Calls 15

SetLevelFunction · 0.92
WithErrorFunction · 0.92
DebugFunction · 0.92
WaitBPChainServiceFunction · 0.92
WithFieldFunction · 0.92
InitFunction · 0.85
DropFunction · 0.85
ErrorMethod · 0.80
DoMethod · 0.80
FatalMethod · 0.80
FatalfMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected