2
0
Files
pgx/helper_test.go
T
Jack Christensen 5b345e80e1 Remove SelectValueTo
Benchmarks revealed that it is no longer performant enough to pull
its own wait. Using go_db_bench to copy JSON results to HTTP responses
it was ~20% *slower* for ~4BK responses and less than 10% faster for
+1MB responses.

The the performance problem was in io.CopyN / io.Copy. io.Copy
allocates a 32KB buffer if it doesn't have io.WriterTo or io.ReaderFrom
available. This extra alloc on every request was more expensive than
just reading the result into a string and writing it out to the response
body.

Tests indicated that if MsgReader implemented a custom Copy that used a
shared buffer it might have a few percent performance advantage. But the
additional complexity is not worth the performance gain.
2014-07-05 09:32:47 -05:00

44 lines
1.1 KiB
Go

package pgx_test
import (
"github.com/jackc/pgx"
"testing"
)
func mustConnect(t testing.TB, config pgx.ConnConfig) *pgx.Conn {
conn, err := pgx.Connect(config)
if err != nil {
t.Fatalf("Unable to establish connection: %v", err)
}
return conn
}
func closeConn(t testing.TB, conn *pgx.Conn) {
err := conn.Close()
if err != nil {
t.Fatalf("conn.Close unexpectedly failed: %v", err)
}
}
func mustPrepare(t testing.TB, conn *pgx.Conn, name, sql string) {
if _, err := conn.Prepare(name, sql); err != nil {
t.Fatalf("Could not prepare %v: %v", name, err)
}
}
func mustExec(t testing.TB, conn *pgx.Conn, sql string, arguments ...interface{}) (commandTag pgx.CommandTag) {
var err error
if commandTag, err = conn.Exec(sql, arguments...); err != nil {
t.Fatalf("Exec unexpectedly failed with %v: %v", sql, err)
}
return
}
func mustSelectValue(t testing.TB, conn *pgx.Conn, sql string, arguments ...interface{}) (value interface{}) {
var err error
if value, err = conn.SelectValue(sql, arguments...); err != nil {
t.Fatalf("SelectValue unexpectedly failed with %v: %v", sql, err)
}
return
}