Debian Codegraph @

test/fixedbugs/bug369.dir/main.go

raw
1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package main
6
7 import (
8 "flag"
9 "os"
10 "runtime"
11 "testing"
12
13 fast "./fast"
14 slow "./slow"
15 )
16
17 var buf = make([]byte, 1048576)
18
19 func BenchmarkFastNonASCII(b *testing.B) {
20 for i := 0; i < b.N; i++ {
21 fast.NonASCII(buf, 0)
22 }
23 }
24
25 func BenchmarkSlowNonASCII(b *testing.B) {
26 for i := 0; i < b.N; i++ {
27 slow.NonASCII(buf, 0)
28 }
29 }
30
31 func main() {
32 testing.Init()
33 os.Args = []string{os.Args[0], "-test.benchtime=100ms"}
34 flag.Parse()
35
36 rslow := testing.Benchmark(BenchmarkSlowNonASCII)
37 rfast := testing.Benchmark(BenchmarkFastNonASCII)
38 tslow := rslow.NsPerOp()
39 tfast := rfast.NsPerOp()
40
41 // Optimization should be good for at least 2x, but be forgiving.
42 // On the ARM simulator we see closer to 1.5x.
43 speedup := float64(tslow) / float64(tfast)
44 want := 1.8
45 if runtime.GOARCH == "arm" {
46 want = 1.3
47 }
48 if speedup < want {
49 // TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on
50 // a Lenovo x200 (linux-amd64) laptop.
51 // println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want)
52 // println("not fast enough")
53 // os.Exit(1)
54 }
55 }