From b830e2ddf3ed719889d1c11da8d73ef09d82a68b Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Tue, 5 Nov 2013 23:08:55 -0600 Subject: [PATCH] Add benchmarks for readVarString. This commit adds a few benchmarks for the readVarString function. --- bench_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/bench_test.go b/bench_test.go index 2927f4ee..d5c84343 100644 --- a/bench_test.go +++ b/bench_test.go @@ -78,3 +78,21 @@ func BenchmarkReadVarInt9(b *testing.B) { btcwire.TstReadVarInt(bytes.NewBuffer(buf), 0) } } + +// BenchmarkReadVarStr4 performs a benchmark on how long it takes to read a +// four byte variable length string. +func BenchmarkReadVarStr4(b *testing.B) { + buf := []byte{0x04, 't', 'e', 's', 't'} + for i := 0; i < b.N; i++ { + btcwire.TstReadVarString(bytes.NewBuffer(buf), 0) + } +} + +// BenchmarkReadVarStr10 performs a benchmark on how long it takes to read a +// ten byte variable length string. +func BenchmarkReadVarStr10(b *testing.B) { + buf := []byte{0x0a, 't', 'e', 's', 't', '0', '1', '2', '3', '4', '5'} + for i := 0; i < b.N; i++ { + btcwire.TstReadVarString(bytes.NewBuffer(buf), 0) + } +}