Skip to content

Commit dd7b87c

Browse files
committed
Add benchmark for interpolateParams()
1 parent 04866ee commit dd7b87c

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

benchmark_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,13 @@ package mysql
1111
import (
1212
"bytes"
1313
"database/sql"
14+
"database/sql/driver"
15+
"math"
1416
"strings"
1517
"sync"
1618
"sync/atomic"
1719
"testing"
20+
"time"
1821
)
1922

2023
type TB testing.B
@@ -210,3 +213,27 @@ func BenchmarkRoundtripBin(b *testing.B) {
210213
rows.Close()
211214
}
212215
}
216+
217+
func BenchmarkInterpolation(b *testing.B) {
218+
mc := &mysqlConn{
219+
cfg: &config{interpolateParams: true},
220+
maxPacketAllowed: maxPacketSize,
221+
maxWriteSize: maxPacketSize - 1,
222+
}
223+
224+
args := []driver.Value{
225+
42424242,
226+
math.Pi,
227+
false,
228+
time.Unix(1423411542, 807015000),
229+
[]byte("bytes containing special chars ' \" \a \x00"),
230+
"string containing special chars ' \" \a \x00",
231+
}
232+
q := "SELECT ?, ?, ?, ?, ?, ?"
233+
234+
b.ReportAllocs()
235+
b.ResetTimer()
236+
for i := 0; i < b.N; i++ {
237+
mc.interpolateParams(q, args)
238+
}
239+
}

0 commit comments

Comments
 (0)