os: add Expand benchmarks

Change-Id: I68e65591cc50433f97a97027e3ae3b452451adf2
Reviewed-on: https://go-review.googlesource.com/106696
Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
Josh Bleecher Snyder 2018-04-12 11:23:33 -07:00
parent 7da88b83d5
commit 3cb067d70d
1 changed files with 16 additions and 0 deletions

View File

@ -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++ {