Commit e9bc0c5d authored by Russ Cox's avatar Russ Cox

os: fix type check error in benchmark

Previously, 's' was only written to, never read,
which is disallowed by the spec. cmd/compile
has a bug where it doesn't notice this when a
closure is involved, but go/types does notice,
which was making "go vet" fail.

This CL moves the variable into the closure
and also makes sure to use it.

Change-Id: I2d83fb6b5c1c9018df03533e966cbdf455f83bf9
Reviewed-on: https://go-review.googlesource.com/108556
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent be012e1e
...@@ -62,19 +62,24 @@ func TestExpand(t *testing.T) { ...@@ -62,19 +62,24 @@ func TestExpand(t *testing.T) {
} }
} }
var global interface{}
func BenchmarkExpand(b *testing.B) { func BenchmarkExpand(b *testing.B) {
var s string
b.Run("noop", func(b *testing.B) { b.Run("noop", func(b *testing.B) {
var s string
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
s = Expand("tick tick tick tick", func(string) string { return "" }) s = Expand("tick tick tick tick", func(string) string { return "" })
} }
global = s
}) })
b.Run("multiple", func(b *testing.B) { b.Run("multiple", func(b *testing.B) {
var s string
b.ReportAllocs() b.ReportAllocs()
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
s = Expand("$a $a $a $a", func(string) string { return "boom" }) s = Expand("$a $a $a $a", func(string) string { return "boom" })
} }
global = s
}) })
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment