File tree 1 file changed +109
-0
lines changed
1 file changed +109
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Swaggest \JsonDiff \JsonDiff ;
4
+
5
+ class DiffBench
6
+ {
7
+ static $ simpleOriginal ;
8
+ static $ simpleNew ;
9
+
10
+ static $ original ;
11
+ static $ new ;
12
+
13
+ public function benchSimpleSkipPatch ()
14
+ {
15
+ new JsonDiff (self ::$ simpleOriginal , self ::$ simpleNew , JsonDiff::REARRANGE_ARRAYS );
16
+ }
17
+
18
+ public function benchSimpleRearrange ()
19
+ {
20
+ new JsonDiff (self ::$ simpleOriginal , self ::$ simpleNew , JsonDiff::REARRANGE_ARRAYS );
21
+ }
22
+
23
+ public function benchSkipPatch ()
24
+ {
25
+ new JsonDiff (self ::$ original , self ::$ new , JsonDiff::REARRANGE_ARRAYS );
26
+ }
27
+
28
+ public function benchRearrange ()
29
+ {
30
+ new JsonDiff (self ::$ original , self ::$ new , JsonDiff::REARRANGE_ARRAYS );
31
+ }
32
+
33
+ public function benchStopOnDiff ()
34
+ {
35
+ new JsonDiff (self ::$ original , self ::$ new , JsonDiff::STOP_ON_DIFF );
36
+ }
37
+
38
+
39
+ static function init ()
40
+ {
41
+ self ::$ simpleOriginal = (object )(array ("root " => (object )array ("a " => 1 , "b " => 2 )));
42
+ self ::$ simpleNew = (object )(array ("root " => (object )array ("b " => 3 , "c " => 4 )));
43
+ self ::$ original = json_decode (<<<'JSON'
44
+ {
45
+ "key1": [
46
+ 4,
47
+ 1,
48
+ 2,
49
+ 3
50
+ ],
51
+ "key2": 2,
52
+ "key3": {
53
+ "sub0": 0,
54
+ "sub1": "a",
55
+ "sub2": "b"
56
+ },
57
+ "key4": [
58
+ {
59
+ "a": 1,
60
+ "b": true
61
+ },
62
+ {
63
+ "a": 2,
64
+ "b": false
65
+ },
66
+ {
67
+ "a": 3
68
+ }
69
+ ]
70
+ }
71
+ JSON
72
+ );
73
+
74
+ self ::$ new = json_decode (<<<'JSON'
75
+ {
76
+ "key5": "wat",
77
+ "key1": [
78
+ 5,
79
+ 1,
80
+ 2,
81
+ 3
82
+ ],
83
+ "key4": [
84
+ {
85
+ "c": false,
86
+ "a": 2
87
+ },
88
+ {
89
+ "a": 1,
90
+ "b": true
91
+ },
92
+ {
93
+ "c": 1,
94
+ "a": 3
95
+ }
96
+ ],
97
+ "key3": {
98
+ "sub3": 0,
99
+ "sub2": false,
100
+ "sub1": "c"
101
+ }
102
+ }
103
+ JSON
104
+ );
105
+ }
106
+
107
+ }
108
+
109
+ DiffBench::init ();
You can’t perform that action at this time.
0 commit comments