-
Notifications
You must be signed in to change notification settings - Fork 6
/
json_test.go
72 lines (64 loc) · 1.54 KB
/
json_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
package test
import (
"github.com/tidwall/gjson"
"github.com/ChengjinWu/gojson"
gojson22 "github.com/widuu/gojson"
"fmt"
"io/ioutil"
"testing"
"time"
)
const (
testCount = 1000000
memCount = 10
)
func getJsonData() []byte {
b, err := ioutil.ReadFile("data.json")
if err != nil {
fmt.Print(err)
}
return b
}
func Test_Gojson(t *testing.T) {
data := getJsonData()
urls := make([]string,memCount)
startTime := time.Now()
object,_ := gojson.FromBytes(data)
for i := 0; i < testCount; i++ {
urls[i%memCount] = object.GetJsonObject("owner").GetJsonObject("received_events_url").GetString()
}
t.Log(time.Now().Sub(startTime))
t.Log(urls[:10])
}
func Test_Gjson(t *testing.T) {
data := string(getJsonData())
urls := make([]string,memCount)
startTime := time.Now()
for i := 0; i < testCount; i++ {
urls[i%memCount] = gjson.Get(data, "owner.received_events_url").Str
}
t.Log(time.Now().Sub(startTime))
t.Log(urls[:10])
}
func Test_Gojson22(t *testing.T) {
data := string(getJsonData())
urls := make([]string,memCount)
startTime := time.Now()
for i := 0; i < testCount; i++ {
urls[i%memCount] = gojson22.Json(data).Get("owner").Get("received_events_url").Tostring()
}
t.Log(time.Now().Sub(startTime))
t.Log(urls[:10])
}
//
//func Test_Coding_Gojson(t *testing.T) {
// data := getJsonData()
// urls := make([]string,memCount)
// startTime := time.Now()
// for i := 0; i < testCount; i++ {
// object,_ := gojson.FromBytes(data)
// urls[i%memCount] = object.GetCoding("chengjin")
// }
// t.Log(time.Now().Sub(startTime))
// t.Log(urls[:1])
//}