From 3cb067d70dd3cd0e4eeb5395d9a8da8ebf199d1a Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 12 Apr 2018 11:23:33 -0700 Subject: [PATCH] os: add Expand benchmarks Change-Id: I68e65591cc50433f97a97027e3ae3b452451adf2 Reviewed-on: https://go-review.googlesource.com/106696 Run-TryBot: Josh Bleecher Snyder TryBot-Result: Gobot Gobot Reviewed-by: Brad Fitzpatrick --- src/os/env_test.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/os/env_test.go b/src/os/env_test.go index 78c8fe57cb..0198f1925d 100644 --- a/src/os/env_test.go +++ b/src/os/env_test.go @@ -62,6 +62,22 @@ func TestExpand(t *testing.T) { } } +func BenchmarkExpand(b *testing.B) { + var s string + b.Run("noop", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + s = Expand("tick tick tick tick", func(string) string { return "" }) + } + }) + b.Run("multiple", func(b *testing.B) { + b.ReportAllocs() + for i := 0; i < b.N; i++ { + s = Expand("$a $a $a $a", func(string) string { return "boom" }) + } + }) +} + func TestConsistentEnviron(t *testing.T) { e0 := Environ() for i := 0; i < 10; i++ { -- 2.50.0