Skip to content

Commit 3cf796c

Browse files
committed
use sane value for length of string selected; merged with current master
1 parent f459d79 commit 3cf796c

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

benchmark_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ import (
88

99
var (
1010
// dsn from driver_test.go
11-
sample = []byte(strings.Repeat("0123456789abcdef", 1024*1024))
11+
sample = []byte(strings.Repeat("0123456789abcdef", 1024*1024))
12+
min, max = 16, len(sample)
1213
)
1314

1415
func BenchmarkRoundtripText(b *testing.B) {
@@ -19,7 +20,10 @@ func BenchmarkRoundtripText(b *testing.B) {
1920
defer db.Close()
2021
var result string
2122
for i := 0; i < b.N; i++ {
22-
length := 16 + i%(4*b.N)
23+
length := min + i
24+
if length > max {
25+
length = max
26+
}
2327
test := string(sample[0:length])
2428
rows, err := db.Query("SELECT \"" + test + "\"")
2529
if err != nil {
@@ -54,7 +58,10 @@ func BenchmarkRoundtripPrepared(b *testing.B) {
5458
b.Fatalf("crashed")
5559
}
5660
for i := 0; i < b.N; i++ {
57-
length := 16 + i%(4*b.N)
61+
length := min + i
62+
if length > max {
63+
length = max
64+
}
5865
test := string(sample[0:length])
5966
rows, err := stmt.Query(test)
6067
if err != nil {

0 commit comments

Comments
 (0)