diff options
author | Russ Cox <rsc@golang.org> | 2011-10-03 17:46:36 -0400 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2011-10-03 17:46:36 -0400 |
commit | d2bac7dd534aa4b2ffe75ef88f5804b703d88d11 (patch) | |
tree | c2cb4ba43e66a16a02d0bd4904e297b5aa59ab08 /test/fixedbugs | |
parent | e65ba656977ab00356368d9a0286c1036e770117 (diff) | |
download | go-d2bac7dd534aa4b2ffe75ef88f5804b703d88d11.tar.gz |
5g, 6g, 8g: registerize variables again
My previous CL:
changeset: 9645:ce2e5f44b310
user: Russ Cox <rsc@golang.org>
date: Tue Sep 06 10:24:21 2011 -0400
summary: gc: unify stack frame layout
introduced a bug wherein no variables were
being registerized, making Go programs 2-3x
slower than they had been before.
This CL fixes that bug (along with some others
it was hiding) and adds a test that optimization
makes at least one test case faster.
R=ken2
CC=golang-dev
http://codereview.appspot.com/5174045
Diffstat (limited to 'test/fixedbugs')
-rw-r--r-- | test/fixedbugs/bug369.dir/pkg.go | 15 | ||||
-rw-r--r-- | test/fixedbugs/bug369.go | 57 |
2 files changed, 72 insertions, 0 deletions
diff --git a/test/fixedbugs/bug369.dir/pkg.go b/test/fixedbugs/bug369.dir/pkg.go new file mode 100644 index 000000000..cf5704192 --- /dev/null +++ b/test/fixedbugs/bug369.dir/pkg.go @@ -0,0 +1,15 @@ +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package pkg + +func NonASCII(b []byte, i int) int { + for i = 0; i < len(b); i++ { + if b[i] >= 0x80 { + break + } + } + return i +} + diff --git a/test/fixedbugs/bug369.go b/test/fixedbugs/bug369.go new file mode 100644 index 000000000..fbcdf28f3 --- /dev/null +++ b/test/fixedbugs/bug369.go @@ -0,0 +1,57 @@ +// $G -N -o slow.$A $D/bug369.dir/pkg.go && +// $G -o fast.$A $D/bug369.dir/pkg.go && +// $G $D/$F.go && $L $F.$A && ./$A.out + +// Copyright 2011 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Test that compiling with optimization turned on produces faster code. + +package main + +import ( + "flag" + "os" + "runtime" + "testing" + + fast "./fast" + slow "./slow" +) + +var buf = make([]byte, 1048576) + +func BenchmarkFastNonASCII(b *testing.B) { + for i := 0; i < b.N; i++ { + fast.NonASCII(buf, 0) + } +} + +func BenchmarkSlowNonASCII(b *testing.B) { + for i := 0; i < b.N; i++ { + slow.NonASCII(buf, 0) + } +} + +func main() { + os.Args = []string{os.Args[0], "-test.benchtime=0.1"} + flag.Parse() + + rslow := testing.Benchmark(BenchmarkSlowNonASCII) + rfast := testing.Benchmark(BenchmarkFastNonASCII) + tslow := rslow.NsPerOp() + tfast := rfast.NsPerOp() + + // Optimization should be good for at least 2x, but be forgiving. + // On the ARM simulator we see closer to 1.5x. + speedup := float64(tslow)/float64(tfast) + want := 1.8 + if runtime.GOARCH == "arm" { + want = 1.3 + } + if speedup < want { + println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want) + println("not fast enough") + } +} |