Debian Codegraph @

performance.html

raw
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4 <head>
5 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
6 <meta name="generator" content="AsciiDoc 8.4.5" />
7 <title>JSON module performance comparison under Lua</title>
8 <style type="text/css">
9 /* Debug borders */
10 p, li, dt, dd, div, pre, h1, h2, h3, h4, h5, h6 {
11 /*
12 border: 1px solid red;
13 */
14 }
15
16 body {
17 margin: 1em 5% 1em 5%;
18 }
19
20 a {
21 color: blue;
22 text-decoration: underline;
23 }
24 a:visited {
25 color: fuchsia;
26 }
27
28 em {
29 font-style: italic;
30 color: navy;
31 }
32
33 strong {
34 font-weight: bold;
35 color: #083194;
36 }
37
38 tt {
39 color: navy;
40 }
41
42 h1, h2, h3, h4, h5, h6 {
43 color: #527bbd;
44 font-family: sans-serif;
45 margin-top: 1.2em;
46 margin-bottom: 0.5em;
47 line-height: 1.3;
48 }
49
50 h1, h2, h3 {
51 border-bottom: 2px solid silver;
52 }
53 h2 {
54 padding-top: 0.5em;
55 }
56 h3 {
57 float: left;
58 }
59 h3 + * {
60 clear: left;
61 }
62
63 div.sectionbody {
64 font-family: serif;
65 margin-left: 0;
66 }
67
68 hr {
69 border: 1px solid silver;
70 }
71
72 p {
73 margin-top: 0.5em;
74 margin-bottom: 0.5em;
75 }
76
77 ul, ol, li > p {
78 margin-top: 0;
79 }
80
81 pre {
82 padding: 0;
83 margin: 0;
84 }
85
86 span#author {
87 color: #527bbd;
88 font-family: sans-serif;
89 font-weight: bold;
90 font-size: 1.1em;
91 }
92 span#email {
93 }
94 span#revnumber, span#revdate, span#revremark {
95 font-family: sans-serif;
96 }
97
98 div#footer {
99 font-family: sans-serif;
100 font-size: small;
101 border-top: 2px solid silver;
102 padding-top: 0.5em;
103 margin-top: 4.0em;
104 }
105 div#footer-text {
106 float: left;
107 padding-bottom: 0.5em;
108 }
109 div#footer-badges {
110 float: right;
111 padding-bottom: 0.5em;
112 }
113
114 div#preamble {
115 margin-top: 1.5em;
116 margin-bottom: 1.5em;
117 }
118 div.tableblock, div.imageblock, div.exampleblock, div.verseblock,
119 div.quoteblock, div.literalblock, div.listingblock, div.sidebarblock,
120 div.admonitionblock {
121 margin-top: 1.5em;
122 margin-bottom: 1.5em;
123 }
124 div.admonitionblock {
125 margin-top: 2.5em;
126 margin-bottom: 2.5em;
127 }
128
129 div.content { /* Block element content. */
130 padding: 0;
131 }
132
133 /* Block element titles. */
134 div.title, caption.title {
135 color: #527bbd;
136 font-family: sans-serif;
137 font-weight: bold;
138 text-align: left;
139 margin-top: 1.0em;
140 margin-bottom: 0.5em;
141 }
142 div.title + * {
143 margin-top: 0;
144 }
145
146 td div.title:first-child {
147 margin-top: 0.0em;
148 }
149 div.content div.title:first-child {
150 margin-top: 0.0em;
151 }
152 div.content + div.title {
153 margin-top: 0.0em;
154 }
155
156 div.sidebarblock > div.content {
157 background: #ffffee;
158 border: 1px solid silver;
159 padding: 0.5em;
160 }
161
162 div.listingblock > div.content {
163 border: 1px solid silver;
164 background: #f4f4f4;
165 padding: 0.5em;
166 }
167
168 div.quoteblock {
169 padding-left: 2.0em;
170 margin-right: 10%;
171 }
172 div.quoteblock > div.attribution {
173 padding-top: 0.5em;
174 text-align: right;
175 }
176
177 div.verseblock {
178 padding-left: 2.0em;
179 margin-right: 10%;
180 }
181 div.verseblock > div.content {
182 white-space: pre;
183 }
184 div.verseblock > div.attribution {
185 padding-top: 0.75em;
186 text-align: left;
187 }
188 /* DEPRECATED: Pre version 8.2.7 verse style literal block. */
189 div.verseblock + div.attribution {
190 text-align: left;
191 }
192
193 div.admonitionblock .icon {
194 vertical-align: top;
195 font-size: 1.1em;
196 font-weight: bold;
197 text-decoration: underline;
198 color: #527bbd;
199 padding-right: 0.5em;
200 }
201 div.admonitionblock td.content {
202 padding-left: 0.5em;
203 border-left: 2px solid silver;
204 }
205
206 div.exampleblock > div.content {
207 border-left: 2px solid silver;
208 padding: 0.5em;
209 }
210
211 div.imageblock div.content { padding-left: 0; }
212 span.image img { border-style: none; }
213 a.image:visited { color: white; }
214
215 dl {
216 margin-top: 0.8em;
217 margin-bottom: 0.8em;
218 }
219 dt {
220 margin-top: 0.5em;
221 margin-bottom: 0;
222 font-style: normal;
223 color: navy;
224 }
225 dd > *:first-child {
226 margin-top: 0.1em;
227 }
228
229 ul, ol {
230 list-style-position: outside;
231 }
232 ol.arabic {
233 list-style-type: decimal;
234 }
235 ol.loweralpha {
236 list-style-type: lower-alpha;
237 }
238 ol.upperalpha {
239 list-style-type: upper-alpha;
240 }
241 ol.lowerroman {
242 list-style-type: lower-roman;
243 }
244 ol.upperroman {
245 list-style-type: upper-roman;
246 }
247
248 div.compact ul, div.compact ol,
249 div.compact p, div.compact p,
250 div.compact div, div.compact div {
251 margin-top: 0.1em;
252 margin-bottom: 0.1em;
253 }
254
255 div.tableblock > table {
256 border: 3px solid #527bbd;
257 }
258 thead {
259 font-family: sans-serif;
260 font-weight: bold;
261 }
262 tfoot {
263 font-weight: bold;
264 }
265 td > div.verse {
266 white-space: pre;
267 }
268 p.table {
269 margin-top: 0;
270 }
271 /* Because the table frame attribute is overriden by CSS in most browsers. */
272 div.tableblock > table[frame="void"] {
273 border-style: none;
274 }
275 div.tableblock > table[frame="hsides"] {
276 border-left-style: none;
277 border-right-style: none;
278 }
279 div.tableblock > table[frame="vsides"] {
280 border-top-style: none;
281 border-bottom-style: none;
282 }
283
284
285 div.hdlist {
286 margin-top: 0.8em;
287 margin-bottom: 0.8em;
288 }
289 div.hdlist tr {
290 padding-bottom: 15px;
291 }
292 dt.hdlist1.strong, td.hdlist1.strong {
293 font-weight: bold;
294 }
295 td.hdlist1 {
296 vertical-align: top;
297 font-style: normal;
298 padding-right: 0.8em;
299 color: navy;
300 }
301 td.hdlist2 {
302 vertical-align: top;
303 }
304 div.hdlist.compact tr {
305 margin: 0;
306 padding-bottom: 0;
307 }
308
309 .comment {
310 background: yellow;
311 }
312
313 @media print {
314 div#footer-badges { display: none; }
315 }
316
317 div#toctitle {
318 color: #527bbd;
319 font-family: sans-serif;
320 font-size: 1.1em;
321 font-weight: bold;
322 margin-top: 1.0em;
323 margin-bottom: 0.1em;
324 }
325
326 div.toclevel1, div.toclevel2, div.toclevel3, div.toclevel4 {
327 margin-top: 0;
328 margin-bottom: 0;
329 }
330 div.toclevel2 {
331 margin-left: 2em;
332 font-size: 0.9em;
333 }
334 div.toclevel3 {
335 margin-left: 4em;
336 font-size: 0.9em;
337 }
338 div.toclevel4 {
339 margin-left: 6em;
340 font-size: 0.9em;
341 }
342 /* Workarounds for IE6's broken and incomplete CSS2. */
343
344 div.sidebar-content {
345 background: #ffffee;
346 border: 1px solid silver;
347 padding: 0.5em;
348 }
349 div.sidebar-title, div.image-title {
350 color: #527bbd;
351 font-family: sans-serif;
352 font-weight: bold;
353 margin-top: 0.0em;
354 margin-bottom: 0.5em;
355 }
356
357 div.listingblock div.content {
358 border: 1px solid silver;
359 background: #f4f4f4;
360 padding: 0.5em;
361 }
362
363 div.quoteblock-attribution {
364 padding-top: 0.5em;
365 text-align: right;
366 }
367
368 div.verseblock-content {
369 white-space: pre;
370 }
371 div.verseblock-attribution {
372 padding-top: 0.75em;
373 text-align: left;
374 }
375
376 div.exampleblock-content {
377 border-left: 2px solid silver;
378 padding-left: 0.5em;
379 }
380
381 /* IE6 sets dynamically generated links as visited. */
382 div#toc a:visited { color: blue; }
383 </style>
384 <script type="text/javascript">
385 /*<![CDATA[*/
386 window.onload = function(){generateToc(2)}
387 /* Author: Mihai Bazon, September 2002
388 * http://students.infoiasi.ro/~mishoo
389 *
390 * Table Of Content generator
391 * Version: 0.4
392 *
393 * Feel free to use this script under the terms of the GNU General Public
394 * License, as long as you do not remove or alter this notice.
395 */
396
397 /* modified by Troy D. Hanson, September 2006. License: GPL */
398 /* modified by Stuart Rackham, October 2006. License: GPL */
399
400 function getText(el) {
401 var text = "";
402 for (var i = el.firstChild; i != null; i = i.nextSibling) {
403 if (i.nodeType == 3 /* Node.TEXT_NODE */) // IE doesn't speak constants.
404 text += i.data;
405 else if (i.firstChild != null)
406 text += getText(i);
407 }
408 return text;
409 }
410
411 function TocEntry(el, text, toclevel) {
412 this.element = el;
413 this.text = text;
414 this.toclevel = toclevel;
415 }
416
417 function tocEntries(el, toclevels) {
418 var result = new Array;
419 var re = new RegExp('[hH]([2-'+(toclevels+1)+'])');
420 // Function that scans the DOM tree for header elements (the DOM2
421 // nodeIterator API would be a better technique but not supported by all
422 // browsers).
423 var iterate = function (el) {
424 for (var i = el.firstChild; i != null; i = i.nextSibling) {
425 if (i.nodeType == 1 /* Node.ELEMENT_NODE */) {
426 var mo = re.exec(i.tagName)
427 if (mo)
428 result[result.length] = new TocEntry(i, getText(i), mo[1]-1);
429 iterate(i);
430 }
431 }
432 }
433 iterate(el);
434 return result;
435 }
436
437 // This function does the work. toclevels = 1..4.
438 function generateToc(toclevels) {
439 var toc = document.getElementById("toc");
440 var entries = tocEntries(document.getElementsByTagName("body")[0], toclevels);
441 for (var i = 0; i < entries.length; ++i) {
442 var entry = entries[i];
443 if (entry.element.id == "")
444 entry.element.id = "toc" + i;
445 var a = document.createElement("a");
446 a.href = "#" + entry.element.id;
447 a.appendChild(document.createTextNode(entry.text));
448 var div = document.createElement("div");
449 div.appendChild(a);
450 div.className = "toclevel" + entry.toclevel;
451 toc.appendChild(div);
452 }
453 if (entries.length == 0)
454 document.getElementById("header").removeChild(toc);
455 }
456 /*]]>*/
457 </script>
458 </head>
459 <body>
460 <div id="header">
461 <h1>JSON module performance comparison under Lua</h1>
462 <span id="author">Mark Pulford</span><br />
463 <span id="email"><tt>&lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</tt></span><br />
464 <span id="revdate">January 22, 2012</span>
465 <div id="toc">
466 <div id="toctitle">Table of Contents</div>
467 <noscript><p><b>JavaScript must be enabled in your browser to display the table of contents.</b></p></noscript>
468 </div>
469 </div>
470 <div id="preamble">
471 <div class="sectionbody">
472 <div class="paragraph"><p>This performance comparison aims to provide a guide of relative
473 performance between several fast and popular JSON modules.</p></div>
474 <div class="paragraph"><p>The examples used in this comparison were mostly sourced from the
475 <a href="http://json.org">JSON website</a> and
476 <a href="http://tools.ietf.org/html/rfc4627">RFC 4627</a>.</p></div>
477 <div class="paragraph"><p>Performance will vary widely between platforms and data sets. These
478 results should only be used as an approximation.</p></div>
479 </div>
480 </div>
481 <h2 id="_modules">1. Modules</h2>
482 <div class="sectionbody">
483 <div class="paragraph"><p>The following JSON modules for Lua were tested:</p></div>
484 <div class="dlist"><dl>
485 <dt class="hdlist1">
486 <a href="http://chiselapp.com/user/dhkolf/repository/dkjson/">DKJSON 2.1</a>
487 </dt>
488 <dd>
489 <div class="ulist"><ul>
490 <li>
491 <p>
492 Lua implementation with no dependencies on other libraries
493 </p>
494 </li>
495 <li>
496 <p>
497 Supports LPeg to improve decode performance
498 </p>
499 </li>
500 </ul></div>
501 </dd>
502 <dt class="hdlist1">
503 <a href="https://github.com/brimworks/lua-yajl">Lua YAJL 2.0</a>
504 </dt>
505 <dd>
506 <div class="ulist"><ul>
507 <li>
508 <p>
509 C wrapper for the YAJL library
510 </p>
511 </li>
512 </ul></div>
513 </dd>
514 <dt class="hdlist1">
515 <a href="http://www.kyne.com.au/%7Emark/software/lua-cjson.php">Lua CSJON 2.0.0</a>
516 </dt>
517 <dd>
518 <div class="ulist"><ul>
519 <li>
520 <p>
521 C implementation with no dependencies on other libraries
522 </p>
523 </li>
524 </ul></div>
525 </dd>
526 </dl></div>
527 </div>
528 <h2 id="_summary">2. Summary</h2>
529 <div class="sectionbody">
530 <div class="paragraph"><p>All modules were built and tested as follows:</p></div>
531 <div class="dlist"><dl>
532 <dt class="hdlist1">
533 DKJSON
534 </dt>
535 <dd>
536 <p>
537 Tested with/without LPeg 10.2.
538 </p>
539 </dd>
540 <dt class="hdlist1">
541 Lua YAJL
542 </dt>
543 <dd>
544 <p>
545 Tested with YAJL 2.0.4.
546 </p>
547 </dd>
548 <dt class="hdlist1">
549 Lua CJSON
550 </dt>
551 <dd>
552 <p>
553 Tested with Libc and internal floating point conversion
554 routines.
555 </p>
556 </dd>
557 </dl></div>
558 <div class="paragraph"><p>The following Lua implementations were used for this comparison:</p></div>
559 <div class="ulist"><ul>
560 <li>
561 <p>
562 <a href="http://www.lua.org">Lua 5.1.4</a> (<em>Lua</em>)
563 </p>
564 </li>
565 <li>
566 <p>
567 <a href="http://www.luajit.org">LuaJIT 2.0.0-beta9</a> (<em>JIT</em>)
568 </p>
569 </li>
570 </ul></div>
571 <div class="paragraph"><p>These results show the number of JSON operations per second sustained by
572 each module. All results have been normalised against the pure Lua
573 DKJSON implementation.</p></div>
574 <div class="literalblock">
575 <div class="title">Decoding performance</div>
576 <div class="content">
577 <pre><tt> | DKJSON | Lua YAJL | Lua CJSON
578 | No LPeg With LPeg | | Libc Internal
579 | Lua JIT Lua JIT | Lua JIT | Lua JIT Lua JIT
580 example1 | 1x 2x 2.6x 3.4x | 7.1x 10x | 14x 20x 14x 20x
581 example2 | 1x 2.2x 2.9x 4.4x | 6.7x 9.9x | 14x 22x 14x 22x
582 example3 | 1x 2.1x 3x 4.3x | 6.9x 9.3x | 14x 21x 15x 22x
583 example4 | 1x 2x 2.5x 3.7x | 7.3x 10x | 12x 19x 12x 20x
584 example5 | 1x 2.2x 3x 4.5x | 7.8x 11x | 16x 24x 16x 24x
585 numbers | 1x 2.2x 2.3x 4x | 4.6x 5.5x | 8.9x 10x 13x 17x
586 rfc-example1 | 1x 2.1x 2.8x 4.3x | 6.1x 8.1x | 13x 19x 14x 21x
587 rfc-example2 | 1x 2.1x 3.1x 4.2x | 7.1x 9.2x | 15x 21x 17x 24x
588 types | 1x 2.2x 2.6x 4.3x | 5.3x 7.4x | 12x 20x 13x 21x
589 -------------|-------------------------|------------|-----------------------
590 = Average =&gt; | 1x 2.1x 2.7x 4.1x | 6.5x 9x | 13x 20x 14x 21x</tt></pre>
591 </div></div>
592 <div class="literalblock">
593 <div class="title">Encoding performance</div>
594 <div class="content">
595 <pre><tt> | DKJSON | Lua YAJL | Lua CJSON
596 | No LPeg With LPeg | | Libc Internal
597 | Lua JIT Lua JIT | Lua JIT | Lua JIT Lua JIT
598 example1 | 1x 1.8x 0.97x 1.6x | 3.1x 5.2x | 23x 29x 23x 29x
599 example2 | 1x 2x 0.97x 1.7x | 2.6x 4.3x | 22x 28x 22x 28x
600 example3 | 1x 1.9x 0.98x 1.6x | 2.8x 4.3x | 13x 15x 16x 18x
601 example4 | 1x 1.7x 0.96x 1.3x | 3.9x 6.1x | 15x 19x 17x 21x
602 example5 | 1x 2x 0.98x 1.7x | 2.7x 4.5x | 20x 23x 20x 23x
603 numbers | 1x 2.3x 1x 2.2x | 1.3x 1.9x | 3.8x 4.1x 4.2x 4.6x
604 rfc-example1 | 1x 1.9x 0.97x 1.6x | 2.2x 3.2x | 8.5x 9.3x 11x 12x
605 rfc-example2 | 1x 1.9x 0.98x 1.6x | 2.6x 3.9x | 10x 11x 17x 19x
606 types | 1x 2.2x 0.97x 2x | 1.2x 1.9x | 11x 13x 12x 14x
607 -------------|-------------------------|------------|-----------------------
608 = Average =&gt; | 1x 1.9x 0.98x 1.7x | 2.5x 3.9x | 14x 17x 16x 19x</tt></pre>
609 </div></div>
610 </div>
611 <div id="footer">
612 <div id="footer-text">
613 Last updated 2012-03-01 22:52:50 CST
614 </div>
615 </div>
616 </body>
617 </html>