performance.html 14 KB

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