1
2
3
4
5
6
7
8
9
10
11
12 package devirt
13
14 import (
15 "testing"
16
17 "example.com/pgo/devirtualize/mult.pkg"
18 )
19
20 func BenchmarkDevirtIface(b *testing.B) {
21 var (
22 a1 Add
23 a2 Sub
24 m1 mult.Mult
25 m2 mult.NegMult
26 )
27
28 ExerciseIface(b.N, a1, a2, m1, m2)
29 }
30
31
32 func TestDevirtIface(t *testing.T) {
33 var (
34 a1 Add
35 a2 Sub
36 m1 mult.Mult
37 m2 mult.NegMult
38 )
39
40 if v := ExerciseIface(10, a1, a2, m1, m2); v != 1176 {
41 t.Errorf("ExerciseIface(10) got %d want 1176", v)
42 }
43 }
44
45 func BenchmarkDevirtFuncConcrete(b *testing.B) {
46 ExerciseFuncConcrete(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
47 }
48
49 func TestDevirtFuncConcrete(t *testing.T) {
50 if v := ExerciseFuncConcrete(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
51 t.Errorf("ExerciseFuncConcrete(10) got %d want 1176", v)
52 }
53 }
54
55 func BenchmarkDevirtFuncField(b *testing.B) {
56 ExerciseFuncField(b.N, AddFn, SubFn, mult.MultFn, mult.NegMultFn)
57 }
58
59 func TestDevirtFuncField(t *testing.T) {
60 if v := ExerciseFuncField(10, AddFn, SubFn, mult.MultFn, mult.NegMultFn); v != 1176 {
61 t.Errorf("ExerciseFuncField(10) got %d want 1176", v)
62 }
63 }
64
65 func BenchmarkDevirtFuncClosure(b *testing.B) {
66 ExerciseFuncClosure(b.N, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure())
67 }
68
69 func TestDevirtFuncClosure(t *testing.T) {
70 if v := ExerciseFuncClosure(10, AddClosure(), SubClosure(), mult.MultClosure(), mult.NegMultClosure()); v != 1176 {
71 t.Errorf("ExerciseFuncClosure(10) got %d want 1176", v)
72 }
73 }
74
View as plain text