From 316b4f202540607dd8a6f3410191b7a29746c0f7 Mon Sep 17 00:00:00 2001 From: Darien Raymond Date: Thu, 8 Dec 2016 17:39:15 +0100 Subject: [PATCH] benchmark buffer pointer vs value --- common/alloc/buffer_test.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/common/alloc/buffer_test.go b/common/alloc/buffer_test.go index 6c0492566..13a1ad04c 100644 --- a/common/alloc/buffer_test.go +++ b/common/alloc/buffer_test.go @@ -81,3 +81,25 @@ func BenchmarkNewLocalBuffer2048(b *testing.B) { buffer.Release() } } + +func BenchmarkBufferValue(b *testing.B) { + x := Buffer{} + doSomething := func(a Buffer) { + _ = a.Len() + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + doSomething(x) + } +} + +func BenchmarkBufferPointer(b *testing.B) { + x := NewSmallBuffer() + doSomething := func(a *Buffer) { + _ = a.Len() + } + b.ResetTimer() + for i := 0; i < b.N; i++ { + doSomething(x) + } +}