mirror of https://github.com/jackc/pgx.git
Added (remove|restore)BinaryEncoders
Makes it so the oid doesn't have to be hard coded into text benchmarks that disable binary encoding.pgx-vs-pq
parent
53da3bb789
commit
c69e638f68
|
@ -52,6 +52,21 @@ func createNarrowTestData(b *testing.B, conn *Connection) {
|
||||||
narrowTestDataLoaded = true
|
narrowTestDataLoaded = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func removeBinaryEncoders() (encoders map[oid]func(*MessageReader, int32) interface{}) {
|
||||||
|
encoders = make(map[oid]func(*MessageReader, int32) interface{})
|
||||||
|
for k, v := range valueTranscoders {
|
||||||
|
encoders[k] = v.DecodeBinary
|
||||||
|
valueTranscoders[k].DecodeBinary = nil
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func restoreBinaryEncoders(encoders map[oid]func(*MessageReader, int32) interface{}) {
|
||||||
|
for k, v := range encoders {
|
||||||
|
valueTranscoders[k].DecodeBinary = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
|
func BenchmarkSelectRowSimpleNarrow(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createNarrowTestData(b, conn)
|
createNarrowTestData(b, conn)
|
||||||
|
@ -262,9 +277,8 @@ func BenchmarkInt2Text(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createInt2TextVsBinaryTestData(b, conn)
|
createInt2TextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(21)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(21)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(21)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectInt16", "select * from t")
|
mustPrepare(b, conn, "selectInt16", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectInt16") }()
|
defer func() { conn.Deallocate("selectInt16") }()
|
||||||
|
@ -322,9 +336,8 @@ func BenchmarkInt4Text(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createInt4TextVsBinaryTestData(b, conn)
|
createInt4TextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(23)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(23)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(23)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectInt32", "select * from t")
|
mustPrepare(b, conn, "selectInt32", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectInt32") }()
|
defer func() { conn.Deallocate("selectInt32") }()
|
||||||
|
@ -382,9 +395,8 @@ func BenchmarkInt8Text(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createInt8TextVsBinaryTestData(b, conn)
|
createInt8TextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(20)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(20)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(20)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectInt64", "select * from t")
|
mustPrepare(b, conn, "selectInt64", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectInt64") }()
|
defer func() { conn.Deallocate("selectInt64") }()
|
||||||
|
@ -442,9 +454,8 @@ func BenchmarkFloat4Text(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createFloat4TextVsBinaryTestData(b, conn)
|
createFloat4TextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(700)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(700)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(700)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectFloat32") }()
|
defer func() { conn.Deallocate("selectFloat32") }()
|
||||||
|
@ -502,9 +513,8 @@ func BenchmarkFloat8Text(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createFloat8TextVsBinaryTestData(b, conn)
|
createFloat8TextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(701)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(701)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(701)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
mustPrepare(b, conn, "selectFloat32", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectFloat32") }()
|
defer func() { conn.Deallocate("selectFloat32") }()
|
||||||
|
@ -562,9 +572,8 @@ func BenchmarkBoolText(b *testing.B) {
|
||||||
conn := getSharedConnection()
|
conn := getSharedConnection()
|
||||||
createBoolTextVsBinaryTestData(b, conn)
|
createBoolTextVsBinaryTestData(b, conn)
|
||||||
|
|
||||||
binaryDecoder := valueTranscoders[oid(16)].DecodeBinary
|
encoders := removeBinaryEncoders()
|
||||||
valueTranscoders[oid(16)].DecodeBinary = nil
|
defer func() { restoreBinaryEncoders(encoders) }()
|
||||||
defer func() { valueTranscoders[oid(16)].DecodeBinary = binaryDecoder }()
|
|
||||||
|
|
||||||
mustPrepare(b, conn, "selectBool", "select * from t")
|
mustPrepare(b, conn, "selectBool", "select * from t")
|
||||||
defer func() { conn.Deallocate("selectBool") }()
|
defer func() { conn.Deallocate("selectBool") }()
|
||||||
|
|
Loading…
Reference in New Issue