From 72680d61f8072c85cb6e03ef51ac1be204736fc3 Mon Sep 17 00:00:00 2001 From: Maxim Ivanov Date: Sun, 19 Apr 2020 11:30:21 +0000 Subject: [PATCH] Move value createion outside of encoding benchmark --- composite_bench_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/composite_bench_test.go b/composite_bench_test.go index a1eba72b..154b2e26 100644 --- a/composite_bench_test.go +++ b/composite_bench_test.go @@ -35,10 +35,10 @@ var x []byte func BenchmarkBinaryEncodingManual(b *testing.B) { buf := make([]byte, 0, 128) ci := pgtype.NewConnInfo() + v := MyCompositeRaw{4, ptrS("ABCDEFG")} b.ResetTimer() for n := 0; n < b.N; n++ { - v := MyCompositeRaw{4, ptrS("ABCDEFG")} buf, _ = v.EncodeBinary(ci, buf[:0]) } x = buf @@ -47,10 +47,10 @@ func BenchmarkBinaryEncodingManual(b *testing.B) { func BenchmarkBinaryEncodingHelper(b *testing.B) { buf := make([]byte, 0, 128) ci := pgtype.NewConnInfo() + v := MyType{4, ptrS("ABCDEFG")} b.ResetTimer() for n := 0; n < b.N; n++ { - v := MyType{4, ptrS("ABCDEFG")} buf, _ = v.EncodeBinary(ci, buf[:0]) } x = buf @@ -59,11 +59,13 @@ func BenchmarkBinaryEncodingHelper(b *testing.B) { func BenchmarkBinaryEncodingRow(b *testing.B) { buf := make([]byte, 0, 128) ci := pgtype.NewConnInfo() + f1 := 2 + f2 := ptrS("bar") b.ResetTimer() for n := 0; n < b.N; n++ { c := pgtype.Composite(&pgtype.Int4{}, &pgtype.Text{}) - c.Set(pgtype.Row(2, "bar")) + c.Set(pgtype.Row(f1, f2)) buf, _ = c.EncodeBinary(ci, buf[:0]) } x = buf