]> Cypherpunks repositories - gostls13.git/commitdiff
os: add Expand benchmarks
authorJosh Bleecher Snyder <josharian@gmail.com>
Thu, 12 Apr 2018 18:23:33 +0000 (11:23 -0700)
committerJosh Bleecher Snyder <josharian@gmail.com>
Thu, 12 Apr 2018 22:18:08 +0000 (22:18 +0000)
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>
src/os/env_test.go

index 78c8fe57cb5d9a4c4b118c8c5e7ba44daaac2968..0198f1925defce70d640814f917f83d9cf15f468 100644 (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++ {