modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/fixedbugs/bug369.dir/main.go (about) 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 os.Args = []string{os.Args[0], "-test.benchtime=100ms"} 33 flag.Parse() 34 35 rslow := testing.Benchmark(BenchmarkSlowNonASCII) 36 rfast := testing.Benchmark(BenchmarkFastNonASCII) 37 tslow := rslow.NsPerOp() 38 tfast := rfast.NsPerOp() 39 40 // Optimization should be good for at least 2x, but be forgiving. 41 // On the ARM simulator we see closer to 1.5x. 42 speedup := float64(tslow) / float64(tfast) 43 want := 1.8 44 if runtime.GOARCH == "arm" { 45 want = 1.3 46 } 47 if speedup < want { 48 // TODO(rsc): doesn't work on linux-amd64 or darwin-amd64 builders, nor on 49 // a Lenovo x200 (linux-amd64) laptop. 50 // println("fast:", tfast, "slow:", tslow, "speedup:", speedup, "want:", want) 51 // println("not fast enough") 52 // os.Exit(1) 53 } 54 }