forked from shixzie/nlp
-
Notifications
You must be signed in to change notification settings - Fork 2
/
benchmark_test.go
111 lines (100 loc) · 1.48 KB
/
benchmark_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
103
104
105
106
107
108
109
110
111
package nlp
import (
"testing"
"time"
)
func BenchmarkNL_P(b *testing.B) {
type T struct {
String string
Int int
Uint uint
Float float32
Time time.Time
Dur time.Duration
}
tSamples := []string{
"string {String}",
"int {Int}",
"uint {Uint}",
"float {Float}",
"time {Time}",
"dur {Dur}",
"string {String} int {Int}",
"string {String} time {Time}",
}
nl := New()
nl.RegisterModel(T{}, tSamples)
err := nl.RegisterModel(T{}, tSamples)
if err != nil {
b.Error(err)
}
err = nl.Learn()
if err != nil {
b.Error(err)
}
tim, err := time.ParseInLocation("01-02-2006_3:04pm", "05-18-1999_6:42pm", time.Local)
if err != nil {
b.Error(err)
}
dur, err := time.ParseDuration("4h2m")
if err != nil {
b.Error(err)
}
cases := []struct {
name string
expression string
want interface{}
}{
{
"string",
"string Hello World",
"Hello World",
},
{
"int",
"int 42",
int(42),
},
{
"uint",
"uint 43",
uint(43),
},
{
"float",
"float 44",
float32(44),
},
{
"time",
"time 05-18-1999_6:42pm",
tim,
},
{
"duration",
"dur 4h2m",
dur,
},
{
"string int",
"string Lmao int 42",
&T{
String: "Lmao",
Int: 42,
},
},
{
"string time",
"string What's Up Boy time 05-18-1999_6:42pm",
&T{
String: "What's Up Boy",
Time: tim,
},
},
}
for _, c := range cases {
b.Run(c.name, func(b *testing.B) {
nl.P(c.expression)
})
}
}