-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathline_test.go
104 lines (90 loc) · 2.56 KB
/
line_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
package bench
import (
"bytes"
"testing"
"github.com/stretchr/testify/assert"
Songmu "github.com/Songmu/go-ltsv"
Wing924 "github.com/Wing924/ltsv"
najeira "github.com/najeira/ltsv"
ymotongpoo "github.com/ymotongpoo/goltsv"
)
var line = []byte("host:127.0.0.1 ident:- user:frank time:[10/Oct/2000:13:55:36 -0700] req:GET /apache_pb3.gif HTTP/1.0 status:200 size:2326 referer:http://www.example.com/start.html ua:Mozilla/4.08 [en] (Win98; I ;Nav)")
var value = map[string]string{
"host": "127.0.0.1",
"ident": "-",
"user": "frank",
"time": "[10/Oct/2000:13:55:36 -0700]",
"req": "GET /apache_pb3.gif HTTP/1.0",
"status": "200",
"size": "2326",
"referer": "http://www.example.com/start.html",
"ua": "Mozilla/4.08 [en] (Win98; I ;Nav)",
}
// Wing924/ltsv
func Test_line_Wing924_ltsv(t *testing.T) {
parser := Wing924.DefaultParser
parser.StrictMode = false
m, err := parser.ParseLineAsMap(line, nil)
assert.NoError(t, err)
assert.EqualValues(t, value, m)
}
func Test_line_Wing924_ltsv_strict(t *testing.T) {
parser := Wing924.DefaultParser
m, err := parser.ParseLineAsMap(line, nil)
assert.NoError(t, err)
assert.EqualValues(t, value, m)
}
func Benchmark_line_Wing924_ltsv(b *testing.B) {
parser := Wing924.DefaultParser
parser.StrictMode = false
m := make(map[string]string, 17)
for i := 0; i < b.N; i++ {
parser.ParseLineAsMap(line, m)
}
}
func Benchmark_line_Wing924_ltsv_strict(b *testing.B) {
parser := Wing924.DefaultParser
m := make(map[string]string, 17)
for i := 0; i < b.N; i++ {
parser.ParseLineAsMap(line, m)
}
}
// Songmu/go-ltsv
func Test_line_Songmu_goltsv(t *testing.T) {
m := make(map[string]string, 17)
err := Songmu.Unmarshal(line, &m)
assert.NoError(t, err)
assert.EqualValues(t, value, m)
}
func Benchmark_line_Songmu_goltsv(b *testing.B) {
m := make(map[string]string, 17)
for i := 0; i < b.N; i++ {
Songmu.Unmarshal(line, &m)
}
}
// ymotongpoo/goltsv
func Test_line_ymotongpoo_goltsv(t *testing.T) {
buf := bytes.NewBuffer(line)
m, err := ymotongpoo.NewReader(buf).Read()
assert.NoError(t, err)
assert.EqualValues(t, value, m)
}
func Benchmark_line_ymotongpoo_goltsv(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := bytes.NewBuffer(line)
ymotongpoo.NewReader(buf).Read()
}
}
// najeira/ltsv
func Test_line_najeira_ltsv(t *testing.T) {
buf := bytes.NewBuffer(line)
m, err := najeira.NewReader(buf).Read()
assert.NoError(t, err)
assert.EqualValues(t, value, m)
}
func Benchmark_line_najeira_ltsv(b *testing.B) {
for i := 0; i < b.N; i++ {
buf := bytes.NewBuffer(line)
najeira.NewReader(buf).Read()
}
}