|
1 | 1 | package json_diff
|
2 | 2 |
|
3 | 3 | import (
|
| 4 | + "fmt" |
4 | 5 | "github.com/520MianXiangDuiXiang520/json-diff/decode"
|
5 |
| - "io/ioutil" |
| 6 | + // "io/ioutil" |
6 | 7 | "testing"
|
7 | 8 | )
|
8 | 9 |
|
9 |
| -func BenchmarkMarshal(b *testing.B) { |
10 |
| - fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
11 |
| - // fileName := "./test_data/hash_test.json" |
12 |
| - input, err := ioutil.ReadFile(fileName) |
13 |
| - if err != nil { |
14 |
| - b.Error("fail to open the ", fileName) |
15 |
| - } |
16 |
| - node, _ := decode.Unmarshal(input) |
17 |
| - b.ResetTimer() |
18 |
| - for i := 0; i < b.N; i++ { |
19 |
| - _, _ = decode.Marshal(node) |
20 |
| - } |
| 10 | +func TestUnmarshal(t *testing.T) { |
| 11 | + json2 := `{ |
| 12 | + "A": 1, "B": [1, 3], "C": [2, 1], "D": 6 |
| 13 | +}` |
| 14 | + node, err := decode.Unmarshal([]byte(json2)) |
| 15 | + fmt.Println(node, err) |
21 | 16 | }
|
22 | 17 |
|
23 |
| -func BenchmarkMarshalOld(b *testing.B) { |
24 |
| - fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
25 |
| - // fileName := "./test_data/hash_test.json" |
26 |
| - input, err := ioutil.ReadFile(fileName) |
27 |
| - if err != nil { |
28 |
| - b.Error("fail to open the ", fileName) |
29 |
| - } |
30 |
| - node, _ := Unmarshal(input) |
31 |
| - b.ResetTimer() |
32 |
| - for i := 0; i < b.N; i++ { |
33 |
| - _, _ = Marshal(node) |
34 |
| - } |
35 |
| -} |
36 |
| - |
37 |
| -func BenchmarkUnmarshal(b *testing.B) { |
38 |
| - fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
39 |
| - // fileName := "./test_data/hash_test.json" |
40 |
| - input, err := ioutil.ReadFile(fileName) |
41 |
| - if err != nil { |
42 |
| - b.Error("fail to open the ", fileName) |
43 |
| - } |
44 |
| - b.ResetTimer() |
45 |
| - for i := 0; i < b.N; i++ { |
46 |
| - _, _ = decode.Unmarshal(input) |
47 |
| - } |
48 |
| -} |
49 |
| - |
50 |
| -func BenchmarkUnmarshalOld(b *testing.B) { |
51 |
| - fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
52 |
| - // fileName := "./test_data/hash_test.json" |
53 |
| - input, err := ioutil.ReadFile(fileName) |
54 |
| - if err != nil { |
55 |
| - b.Error("fail to open the ", fileName) |
56 |
| - } |
57 |
| - b.ResetTimer() |
58 |
| - for i := 0; i < b.N; i++ { |
59 |
| - _, _ = Unmarshal(input) |
60 |
| - } |
61 |
| -} |
| 18 | +// func BenchmarkMarshal(b *testing.B) { |
| 19 | +// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
| 20 | +// // fileName := "./test_data/hash_test.json" |
| 21 | +// input, err := ioutil.ReadFile(fileName) |
| 22 | +// if err != nil { |
| 23 | +// b.Error("fail to open the ", fileName) |
| 24 | +// } |
| 25 | +// node, _ := decode.Unmarshal(input) |
| 26 | +// b.ResetTimer() |
| 27 | +// for i := 0; i < b.N; i++ { |
| 28 | +// _, _ = decode.Marshal(node) |
| 29 | +// } |
| 30 | +// } |
| 31 | +// |
| 32 | +// func BenchmarkMarshalOld(b *testing.B) { |
| 33 | +// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
| 34 | +// // fileName := "./test_data/hash_test.json" |
| 35 | +// input, err := ioutil.ReadFile(fileName) |
| 36 | +// if err != nil { |
| 37 | +// b.Error("fail to open the ", fileName) |
| 38 | +// } |
| 39 | +// node, _ := Unmarshal(input) |
| 40 | +// b.ResetTimer() |
| 41 | +// for i := 0; i < b.N; i++ { |
| 42 | +// _, _ = Marshal(node) |
| 43 | +// } |
| 44 | +// } |
| 45 | +// |
| 46 | +// func BenchmarkUnmarshal(b *testing.B) { |
| 47 | +// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
| 48 | +// // fileName := "./test_data/hash_test.json" |
| 49 | +// input, err := ioutil.ReadFile(fileName) |
| 50 | +// if err != nil { |
| 51 | +// b.Error("fail to open the ", fileName) |
| 52 | +// } |
| 53 | +// b.ResetTimer() |
| 54 | +// for i := 0; i < b.N; i++ { |
| 55 | +// _, _ = decode.Unmarshal(input) |
| 56 | +// } |
| 57 | +// } |
| 58 | +// |
| 59 | +// func BenchmarkUnmarshalOld(b *testing.B) { |
| 60 | +// fileName := "./test_data/deepcopy_test/deepcopy_speed_test.json" |
| 61 | +// // fileName := "./test_data/hash_test.json" |
| 62 | +// input, err := ioutil.ReadFile(fileName) |
| 63 | +// if err != nil { |
| 64 | +// b.Error("fail to open the ", fileName) |
| 65 | +// } |
| 66 | +// b.ResetTimer() |
| 67 | +// for i := 0; i < b.N; i++ { |
| 68 | +// _, _ = Unmarshal(input) |
| 69 | +// } |
| 70 | +// } |
0 commit comments