| 113 | } |
| 114 | |
| 115 | func 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 |
| 150 | var roundtripSample []byte |