Don't panic!
This commit is contained in:
+22
-25
@@ -1,7 +1,6 @@
|
||||
package pgx_test
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/JackC/pgx"
|
||||
"math/rand"
|
||||
"testing"
|
||||
@@ -22,7 +21,7 @@ func createNarrowTestData(b *testing.B, conn *pgx.Connection) {
|
||||
return
|
||||
}
|
||||
|
||||
if _, err := conn.Execute(`
|
||||
mustExecute(b, conn, `
|
||||
drop table if exists narrow;
|
||||
|
||||
create table narrow(
|
||||
@@ -38,9 +37,7 @@ func createNarrowTestData(b *testing.B, conn *pgx.Connection) {
|
||||
from generate_series(1, 10000);
|
||||
|
||||
analyze narrow;
|
||||
`); err != nil {
|
||||
panic(fmt.Sprintf("Unable to create narrow test data: %v", err))
|
||||
}
|
||||
`)
|
||||
|
||||
mustPrepare(b, conn, "getNarrowById", "select * from narrow where id=$1")
|
||||
mustPrepare(b, conn, "getMultipleNarrowById", "select * from narrow where id between $1 and $2")
|
||||
@@ -64,7 +61,7 @@ func restoreBinaryEncoders(encoders map[pgx.Oid]func(*pgx.MessageReader, int32)
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createNarrowTestData(b, conn)
|
||||
|
||||
// Get random ids outside of timing
|
||||
@@ -80,7 +77,7 @@ func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowPreparedNarrow(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createNarrowTestData(b, conn)
|
||||
|
||||
// Get random ids outside of timing
|
||||
@@ -96,7 +93,7 @@ func BenchmarkSelectRowPreparedNarrow(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowsSimpleNarrow(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createNarrowTestData(b, conn)
|
||||
|
||||
// Get random ids outside of timing
|
||||
@@ -112,7 +109,7 @@ func BenchmarkSelectRowsSimpleNarrow(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowsPreparedNarrow(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createNarrowTestData(b, conn)
|
||||
|
||||
// Get random ids outside of timing
|
||||
@@ -199,7 +196,7 @@ func createJoinsTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowsSimpleJoins(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createJoinsTestData(b, conn)
|
||||
|
||||
sql := `
|
||||
@@ -219,7 +216,7 @@ func BenchmarkSelectRowsSimpleJoins(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkSelectRowsPreparedJoins(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createJoinsTestData(b, conn)
|
||||
|
||||
b.ResetTimer()
|
||||
@@ -254,7 +251,7 @@ func createInt2TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkInt2Text(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt2TextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -270,7 +267,7 @@ func BenchmarkInt2Text(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkInt2Binary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt2TextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectInt16", "select * from t")
|
||||
defer func() { conn.Deallocate("selectInt16") }()
|
||||
@@ -307,7 +304,7 @@ func createInt4TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkInt4Text(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt4TextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -323,7 +320,7 @@ func BenchmarkInt4Text(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkInt4Binary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt4TextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectInt32", "select * from t")
|
||||
defer func() { conn.Deallocate("selectInt32") }()
|
||||
@@ -360,7 +357,7 @@ func createInt8TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkInt8Text(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt8TextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -376,7 +373,7 @@ func BenchmarkInt8Text(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkInt8Binary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createInt8TextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectInt64", "select * from t")
|
||||
defer func() { conn.Deallocate("selectInt64") }()
|
||||
@@ -413,7 +410,7 @@ func createFloat4TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkFloat4Text(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createFloat4TextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -429,7 +426,7 @@ func BenchmarkFloat4Text(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkFloat4Binary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createFloat4TextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
||||
defer func() { conn.Deallocate("selectFloat32") }()
|
||||
@@ -466,7 +463,7 @@ func createFloat8TextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkFloat8Text(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createFloat8TextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -482,7 +479,7 @@ func BenchmarkFloat8Text(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkFloat8Binary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createFloat8TextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
||||
defer func() { conn.Deallocate("selectFloat32") }()
|
||||
@@ -519,7 +516,7 @@ func createBoolTextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkBoolText(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createBoolTextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -535,7 +532,7 @@ func BenchmarkBoolText(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkBoolBinary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createBoolTextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectBool", "select * from t")
|
||||
defer func() { conn.Deallocate("selectBool") }()
|
||||
@@ -576,7 +573,7 @@ func createTimestampTzTextVsBinaryTestData(b *testing.B, conn *pgx.Connection) {
|
||||
}
|
||||
|
||||
func BenchmarkTimestampTzText(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createTimestampTzTextVsBinaryTestData(b, conn)
|
||||
|
||||
encoders := removeBinaryEncoders()
|
||||
@@ -592,7 +589,7 @@ func BenchmarkTimestampTzText(b *testing.B) {
|
||||
}
|
||||
|
||||
func BenchmarkTimestampTzBinary(b *testing.B) {
|
||||
conn := getSharedConnection()
|
||||
conn := getSharedConnection(b)
|
||||
createTimestampTzTextVsBinaryTestData(b, conn)
|
||||
mustPrepare(b, conn, "selectTimestampTz", "select * from t")
|
||||
defer func() { conn.Deallocate("selectTimestampTz") }()
|
||||
|
||||
Reference in New Issue
Block a user