From: Josh Bleecher Snyder Date: Thu, 12 Apr 2018 18:23:33 +0000 (-0700) Subject: os: add Expand benchmarks X-Git-Tag: go1.11beta1~847 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=3cb067d70dd3cd0e4eeb5395d9a8da8ebf199d1a;p=gostls13.git 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 --- 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++ {