MCPcopy
hub / github.com/go-sql-driver/mysql / BenchmarkExec

Function BenchmarkExec

benchmark_test.go:115–147  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

113}
114
115func BenchmarkExec(b *testing.B) {
116 tb := (*TB)(b)
117 db := tb.checkDB(sql.Open(driverNameTest, dsn))
118 db.SetMaxIdleConns(concurrencyLevel)
119 defer db.Close()
120
121 stmt := tb.checkStmt(db.Prepare("DO 1"))
122 defer stmt.Close()
123
124 remain := int64(b.N)
125 var wg sync.WaitGroup
126 wg.Add(concurrencyLevel)
127 defer wg.Wait()
128
129 b.ReportAllocs()
130 b.ResetTimer()
131
132 for range concurrencyLevel {
133 go func() {
134 for {
135 if atomic.AddInt64(&remain, -1) < 0 {
136 wg.Done()
137 return
138 }
139
140 if _, err := stmt.Exec(); err != nil {
141 b.Logf("stmt.Exec failed: %v", err)
142 b.Fail()
143 }
144 }
145 }()
146 }
147}
148
149// data, but no db writes
150var roundtripSample []byte

Callers

nothing calls this directly

Calls 6

checkDBMethod · 0.80
OpenMethod · 0.80
checkStmtMethod · 0.80
PrepareMethod · 0.80
CloseMethod · 0.45
ExecMethod · 0.45

Tested by

no test coverage detected