Source file
test/fixedbugs/issue75764.go
1
2
3
4
5
6
7
8
9 package main
10
11 import (
12 "fmt"
13 "runtime"
14 "time"
15 )
16
17 type I interface {
18 foo() time.Duration
19 }
20
21 type base struct {
22 }
23
24 func (b *base) foo() time.Duration {
25 t := time.Now()
26 var pcs [10]uintptr
27 runtime.Callers(1, pcs[:])
28 return time.Since(t)
29 }
30
31 type wrap struct {
32 I
33 data int
34 }
35
36
37 func best(f func() time.Duration) time.Duration {
38 m := f()
39 for range 9 {
40 m = min(m, f())
41 }
42 return m
43 }
44
45 func main() {
46 if runtime.GOARCH == "wasm" {
47
48 return
49 }
50 var i I = &base{}
51 for x := range 1000 {
52 i = &wrap{I: i, data: x}
53 }
54 short := best(i.foo)
55 for x := range 9000 {
56 i = &wrap{I: i, data: x}
57 }
58 long := best(i.foo)
59
60 ratio := long.Seconds() / short.Seconds()
61
62
63
64
65
66 allowed := 5.0
67 if ratio >= allowed {
68 fmt.Printf("short: %v\nlong: %v\nratio: %v\nallowed: %v\n", short, long, ratio, allowed)
69 }
70 }
71
View as plain text