-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalue_test.go
More file actions
48 lines (39 loc) · 826 Bytes
/
value_test.go
File metadata and controls
48 lines (39 loc) · 826 Bytes
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
// Copyright (c) 2015 Datacratic. All rights reserved.
package jq
import (
"encoding/json"
"sync"
"testing"
)
func TestParseJSON(t *testing.T) {
n := len(samples)
for i := 0; i < n; i++ {
sample := samples[i]
v := Value{}
if err := v.Unmarshal(sample); err != nil {
t.Fatal(err)
}
}
}
func BenchmarkParseGoJSON(b *testing.B) {
b.ResetTimer()
for i := 0; i < b.N; i++ {
m := make(map[string]interface{})
if err := json.Unmarshal(samples[i%len(samples)], &m); err != nil {
b.Fatal(err)
}
}
}
func BenchmarkParseJSON(b *testing.B) {
valuePool := sync.Pool{
New: func() interface{} { return &Value{} },
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
v := valuePool.Get().(*Value)
if err := v.Unmarshal(samples[i%len(samples)]); err != nil {
b.Fatal(err)
}
valuePool.Put(v)
}
}