|
1 |
| -// $G -N -o slow.$A $D/bug369.dir/pkg.go && |
2 |
| -// $G -o fast.$A $D/bug369.dir/pkg.go && |
| 1 | +// +build !nacl |
3 | 2 | // run
|
4 | 3 |
|
5 |
| -// NOTE: This test is not run by 'run.go' and so not run by all.bash. |
6 |
| -// To run this test you must use the ./run shell script. |
7 |
| - |
8 | 4 | // Copyright 2011 The Go Authors. All rights reserved.
|
9 | 5 | // Use of this source code is governed by a BSD-style
|
10 | 6 | // license that can be found in the LICENSE file.
|
|
14 | 10 | package main
|
15 | 11 |
|
16 | 12 | import (
|
17 |
| - "flag" |
| 13 | + "fmt" |
| 14 | + "go/build" |
18 | 15 | "os"
|
19 |
| - "runtime" |
20 |
| - "testing" |
21 |
| - |
22 |
| - fast "./fast" |
23 |
| - slow "./slow" |
| 16 | + "os/exec" |
| 17 | + "path/filepath" |
24 | 18 | )
|
25 | 19 |
|
26 |
| -var buf = make([]byte, 1048576) |
27 |
| - |
28 |
| -func BenchmarkFastNonASCII(b *testing.B) { |
29 |
| - for i := 0; i < b.N; i++ { |
30 |
| - fast.NonASCII(buf, 0) |
31 |
| - } |
| 20 | +func main() { |
| 21 | + a, err := build.ArchChar(build.Default.GOARCH) |
| 22 | + check(err) |
| 23 | + |
| 24 | + err = os.Chdir(filepath.Join(".", "fixedbugs", "bug369.dir")) |
| 25 | + check(err) |
| 26 | + |
| 27 | + run("go", "tool", a+"g", "-N", "-o", "slow."+a, "pkg.go") |
| 28 | + run("go", "tool", a+"g", "-o", "fast."+a, "pkg.go") |
| 29 | + run("go", "tool", a+"g", "-o", "main."+a, "main.go") |
| 30 | + run("go", "tool", a+"l", "-o", "a.exe", "main."+a) |
| 31 | + run("." + string(filepath.Separator) + "a.exe") |
| 32 | + |
| 33 | + os.Remove("slow." + a) |
| 34 | + os.Remove("fast." + a) |
| 35 | + os.Remove("main." + a) |
| 36 | + os.Remove("a.exe") |
32 | 37 | }
|
33 | 38 |
|
34 |
| -func BenchmarkSlowNonASCII(b *testing.B) { |
35 |
| - for i := 0; i < b.N; i++ { |
36 |
| - slow.NonASCII(buf, 0) |
| 39 | +func run(name string, args ...string) { |
| 40 | + cmd := exec.Command(name, args...) |
| 41 | + out, err := cmd.CombinedOutput() |
| 42 | + if err != nil { |
| 43 | + fmt.Println(string(out)) |
| 44 | + fmt.Println(err) |
| 45 | + os.Exit(1) |
37 | 46 | }
|
38 | 47 | }
|
39 | 48 |
|
40 |
| -func main() { |
41 |
| - os.Args = []string{os.Args[0], "-test.benchtime=100ms"} |
42 |
| - flag.Parse() |
43 |
| - |
44 |
| - rslow := testing.Benchmark(BenchmarkSlowNonASCII) |
45 |
| - rfast := testing.Benchmark(BenchmarkFastNonASCII) |
46 |
| - tslow := rslow.NsPerOp() |
47 |
| - tfast := rfast.NsPerOp() |
48 |
| - |
49 |
| - // Optimization should be good for at least 2x, but be forgiving. |
50 |
| - // On the ARM simulator we see closer to 1.5x. |
51 |
| - speedup := float64(tslow)/float64(tfast) |
52 |
| - want := 1.8 |
53 |
| - if runtime.GOARCH == "arm" { |
54 |
| - want = 1.3 |
55 |
| - } |
56 |
| - if speedup < want { |
57 |
| - // TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on |
58 |
| - // a Lenovo x200 (linux-amd64) laptop. |
59 |
| - //println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want) |
60 |
| - //println("not fast enough") |
| 49 | +func check(err error) { |
| 50 | + if err != nil { |
| 51 | + fmt.Println(err) |
| 52 | + os.Exit(1) |
61 | 53 | }
|
62 | 54 | }
|
0 commit comments