1
2
3
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
42
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
50
51
52
53
54 }
55 }
56
View as plain text