-
Notifications
You must be signed in to change notification settings - Fork 0
/
method_test.go
102 lines (92 loc) · 2.12 KB
/
method_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package call_test
import (
"fmt"
"net/http"
"testing"
"github.com/nofeaturesonlybugs/call"
"github.com/nofeaturesonlybugs/call/examples"
)
func Test_Method_Call(t *testing.T) {
t.Run("HTTP.Handler", func(t *testing.T) {
var talk examples.HTTP
instance := call.Stat(talk)
m, _ := instance.Methods.Named("Handler")
//
args := m.Args()
m.Call(args)
})
t.Run("ManyArgs.Many", func(t *testing.T) {
var many examples.ManyArgs
instance := call.Stat(many)
m, _ := instance.Methods.Named("Many")
//
args := m.Args()
m.Call(args)
})
}
func ExampleMethods_Named() {
var A examples.MapSession
var am call.Method
var err error
a := call.Stat(A)
if am, err = a.Methods.Named("Get"); err != nil {
fmt.Println(err)
return
}
fmt.Println(am.Pretty())
if am, err = a.Methods.Named("MethodDoesNotExist"); err != nil {
fmt.Println(err)
return
}
// Output: Get (examples.MapSession, string) interface {}
// not found
}
func Benchmark_Method_Call_StandardBaseline(b *testing.B) {
var w *http.ResponseWriter
var req **http.Request
var sess *examples.Session
var talk examples.HTTP
for k := 0; k < b.N; k++ {
// Calling Handler(nil, nil, nil, struct{...}) is a ridiculously unfair comparison.
// We create these values to indicate some small cost in instantiating and providing useful
// values.
w = new(http.ResponseWriter)
req = new(*http.Request)
sess = new(examples.Session)
talk.Handler(*w, *req, *sess, struct {
Username string "form:\"username\""
Password string "form:\"password\""
}{
Username: "hi",
Password: "bye",
})
}
}
func Benchmark_Method_Call_Current(b *testing.B) {
var talk examples.HTTP
instance := call.Stat(talk)
m, err := instance.Methods.Named("Handler")
if err != nil {
b.Fatal(err)
}
//
b.ResetTimer()
var args *call.Args
for k := 0; k < b.N; k++ {
args = m.Args()
m.Call(args)
}
}
func Benchmark_Method_Call_ManyArgs(b *testing.B) {
var many examples.ManyArgs
instance := call.Stat(many)
m, err := instance.Methods.Named("Many")
if err != nil {
b.Fatal(err)
}
b.ResetTimer()
for k := 0; k < b.N; k++ {
args := m.Args()
m.Call(args)
}
}