Przeglądaj źródła

use sane value for length of string selected; merged with current master

Arne Hormann 12 lat temu
rodzic
commit
3cf796c575
1 zmienionych plików z 10 dodań i 3 usunięć
  1. 10 3
      benchmark_test.go

+ 10 - 3
benchmark_test.go

@@ -8,7 +8,8 @@ import (
 
 var (
 	// dsn from driver_test.go
-	sample = []byte(strings.Repeat("0123456789abcdef", 1024*1024))
+	sample   = []byte(strings.Repeat("0123456789abcdef", 1024*1024))
+	min, max = 16, len(sample)
 )
 
 func BenchmarkRoundtripText(b *testing.B) {
@@ -19,7 +20,10 @@ func BenchmarkRoundtripText(b *testing.B) {
 	defer db.Close()
 	var result string
 	for i := 0; i < b.N; i++ {
-		length := 16 + i%(4*b.N)
+		length := min + i
+		if length > max {
+			length = max
+		}
 		test := string(sample[0:length])
 		rows, err := db.Query("SELECT \"" + test + "\"")
 		if err != nil {
@@ -54,7 +58,10 @@ func BenchmarkRoundtripPrepared(b *testing.B) {
 		b.Fatalf("crashed")
 	}
 	for i := 0; i < b.N; i++ {
-		length := 16 + i%(4*b.N)
+		length := min + i
+		if length > max {
+			length = max
+		}
 		test := string(sample[0:length])
 		rows, err := stmt.Query(test)
 		if err != nil {