1====== JSON Data Benchmark Testing ======
2
3
4===== PHP Stopwatch =====
5[[https://www.dokuwiki.org/plugin:stopwatch|Stopwatch plugin]] measures execution time of PHP code:
6  * ''%%<stopwatch reset>%%'' - Resets stopwatch to zero.
7  * ''%%<stopwatch show>%%'' - Show elapsed time in seconds since last reset.
8
9
10===== Recursive JSON load =====
11Here is JSON data with src attribute, which links to itself. So it is recursively loaded 30 times.
12<code>
13<stopwatch reset>
14<json id=cookie path=cookie src=benchmark#cookie display=combined,log*>
15{
16  "name": "Butter cookie",
17  "type": "cookie",
18  "Ingredients": {
19    "eggs": "3",
20    "flour": "500 g",
21    "sugar": "300 g",
22    "butter": "250 g"
23  }
24}
25</json>
26Time elapsed: <stopwatch show>
27</code>
28<stopwatch reset>
29<json id=cookie path=cookie src=benchmark#cookie display=combined,log*>
30{
31  "name": "Butter cookie",
32  "type": "cookie",
33  "Ingredients": {
34    "eggs": "3",
35    "flour": "500 g",
36    "sugar": "300 g",
37    "butter": "250 g"
38  }
39}
40</json>
41Time elapsed: <stopwatch show>
42
43
44===== Load multiple files into JSON array =====
45Here is one long JSON file with random data: [[.1000files:file1]]. For testing purposes it should be copied to different filenames 1000 times. Here is bash command for this:
46<code bash>for i in {2..1000}; do cp file1.txt "file$i.txt"; done</code>
47
48==== Load one file ====
49<stopwatch reset>
50<json path=stack1[] src=.1000files:file1 display=combined,log*></json>
51''%%<json path=stack1[] src=.1000files:file1 display=combined,log*></json>%%''\\
52Time elapsed: <stopwatch show>
53
54==== Load 112 files ====
55<stopwatch reset>
56<json path=stack2[] src=.1000files:file1* display=combined,log*></json>
57''%%<json path=stack2[] src=.1000files:file1* display=combined,log*></json>%%''\\
58Time elapsed: <stopwatch show>
59
60==== Load 1000 files ====
61<stopwatch reset>
62<json path=stack3[] src=.1000files:file*></json>
63''%%<json path=stack3[] src=.1000files:file*></json>%%''\\
64Time elapsed: <stopwatch show>
65
66==== Single item ====
67<stopwatch reset>
68''%%%$stack2.55.0.friends.0.name%%%''\\
69%$stack2.55.0.friends.0.name%\\
70Time elapsed: <stopwatch show>
71
72==== Table of 112 files ====
73<code>
74%$stack2[]{"Name0":0.friends.0.name, "Name1":1.friends.0.name, "Name2":2.friends.0.name, "Name3":3.friends.0.name, "Name4":4.friends.0.name, "Name5":5.friends.0.name, "Name6":6.friends.0.name, "Name7":7.friends.0.name, "Name8":8.friends.0.name}%
75</code>
76<stopwatch reset>
77%$stack2[]{"Name0":0.friends.0.name, "Name1":1.friends.0.name, "Name2":2.friends.0.name, "Name3":3.friends.0.name, "Name4":4.friends.0.name, "Name5":5.friends.0.name, "Name6":6.friends.0.name, "Name7":7.friends.0.name, "Name8":8.friends.0.name}%\\
78Time elapsed: <stopwatch show>
79
80==== Table of 1000 files ====
81<code>
82%$stack3[]{ ... }%
83</code>
84<stopwatch reset>
85%$stack3[]{"Name0":0.friends.0.name, "Name1":1.friends.0.name, "Name2":2.friends.0.name, "Name3":3.friends.0.name, "Name4":4.friends.0.name, "Name5":5.friends.0.name, "Name6":6.friends.0.name, "Name7":7.friends.0.name, "Name8":8.friends.0.name}%\\
86Time elapsed: <stopwatch show>
87
88==== Show JSON data of 112 files ====
89This is most time consuming:
90<code>
91%$stack2 #code#%
92</code>
93<stopwatch reset>
94%$stack2 #code#%
95Time elapsed: <stopwatch show>
96