File tree 1 file changed +33
-1
lines changed
1 file changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -51,7 +51,6 @@ func initDB(b *testing.B, queries ...string) *sql.DB {
51
51
return db
52
52
}
53
53
54
- // by Brad Fitzpatrick
55
54
const concurrencyLevel = 10
56
55
57
56
func BenchmarkQuery (b * testing.B ) {
@@ -93,6 +92,39 @@ func BenchmarkQuery(b *testing.B) {
93
92
}
94
93
}
95
94
95
+ func BenchmarkExec (b * testing.B ) {
96
+ tb := (* TB )(b )
97
+ b .StopTimer ()
98
+ b .ReportAllocs ()
99
+ db := tb .checkDB (sql .Open ("mysql" , dsn ))
100
+ db .SetMaxIdleConns (concurrencyLevel )
101
+ defer db .Close ()
102
+
103
+ stmt := tb .checkStmt (db .Prepare ("DO 1" ))
104
+ defer stmt .Close ()
105
+
106
+ remain := int64 (b .N )
107
+ var wg sync.WaitGroup
108
+ wg .Add (concurrencyLevel )
109
+ defer wg .Wait ()
110
+ b .StartTimer ()
111
+
112
+ for i := 0 ; i < concurrencyLevel ; i ++ {
113
+ go func () {
114
+ for {
115
+ if atomic .AddInt64 (& remain , - 1 ) < 0 {
116
+ wg .Done ()
117
+ return
118
+ }
119
+
120
+ if _ , err := stmt .Exec (); err != nil {
121
+ b .Fatal (err .Error ())
122
+ }
123
+ }
124
+ }()
125
+ }
126
+ }
127
+
96
128
// data, but no db writes
97
129
var roundtripSample []byte
98
130
You can’t perform that action at this time.
0 commit comments