… | |
… | |
242 | =head1 COMPARISON |
242 | =head1 COMPARISON |
243 | |
243 | |
244 | As already mentioned, this module was created because none of the existing |
244 | As already mentioned, this module was created because none of the existing |
245 | JSON modules could be made to work correctly. First I will describe the |
245 | JSON modules could be made to work correctly. First I will describe the |
246 | problems (or pleasures) I encountered with various existing JSON modules, |
246 | problems (or pleasures) I encountered with various existing JSON modules, |
247 | followed by some benchmark values. |
247 | followed by some benchmark values. JSON::XS was designed not to suffer |
|
|
248 | from any of these problems or limitations. |
248 | |
249 | |
249 | =over 4 |
250 | =over 4 |
250 | |
251 | |
251 | =item JSON |
252 | =item JSON |
252 | |
253 | |
… | |
… | |
261 | decode into the number 2. |
262 | decode into the number 2. |
262 | |
263 | |
263 | =item JSON::PC |
264 | =item JSON::PC |
264 | |
265 | |
265 | Very fast. |
266 | Very fast. |
|
|
267 | |
|
|
268 | Undocumented/buggy Unicode handling. |
|
|
269 | |
|
|
270 | No roundtripping. |
|
|
271 | |
|
|
272 | Has problems handling many Perl values (e.g. regex results and other magic |
|
|
273 | values will make it croak). |
|
|
274 | |
|
|
275 | Does not even generate valid JSON (C<{1,2}> gets converted to C<{1:2}> |
|
|
276 | which is not a valid JSON string. |
|
|
277 | |
|
|
278 | Unmaintained (maintainer unresponsive for many months, bugs are not |
|
|
279 | getting fixed). |
|
|
280 | |
|
|
281 | =item JSON::Syck |
|
|
282 | |
|
|
283 | Very buggy (often crashes). |
266 | |
284 | |
267 | Very inflexible (no human-readable format supported, format pretty much |
285 | Very inflexible (no human-readable format supported, format pretty much |
268 | undocumented. I need at least a format for easy reading by humans and a |
286 | undocumented. I need at least a format for easy reading by humans and a |
269 | single-line compact format for use in a protocol, and preferably a way to |
287 | single-line compact format for use in a protocol, and preferably a way to |
270 | generate ASCII-only JSON strings). |
288 | generate ASCII-only JSON strings). |
271 | |
|
|
272 | Undocumented/buggy Unicode handling. |
|
|
273 | |
|
|
274 | No roundtripping. |
|
|
275 | |
|
|
276 | Has problems handling many Perl values. |
|
|
277 | |
|
|
278 | Does not even generate valid JSON (C<{1,2}> gets converted to C<{1:2}> |
|
|
279 | which is not a valid JSON string. |
|
|
280 | |
|
|
281 | Unmaintained (maintainer unresponsive for many months, bugs are not |
|
|
282 | getting fixed). |
|
|
283 | |
|
|
284 | =item JSON::Syck |
|
|
285 | |
|
|
286 | Very buggy (often crashes). |
|
|
287 | |
|
|
288 | Very inflexible. |
|
|
289 | |
289 | |
290 | Completely broken (and confusingly documented) Unicode handling (unicode |
290 | Completely broken (and confusingly documented) Unicode handling (unicode |
291 | escapes are not working properly, you need to set ImplicitUnicode to |
291 | escapes are not working properly, you need to set ImplicitUnicode to |
292 | I<different> values on en- and decoding to get symmetric behaviour). |
292 | I<different> values on en- and decoding to get symmetric behaviour). |
293 | |
293 | |
… | |
… | |
316 | |
316 | |
317 | Very inflexible. |
317 | Very inflexible. |
318 | |
318 | |
319 | No roundtripping. |
319 | No roundtripping. |
320 | |
320 | |
|
|
321 | Does not generate valid JSON (key strings are often unquoted, empty keys |
|
|
322 | result in nothing being output) |
|
|
323 | |
321 | Does not check input for validity. |
324 | Does not check input for validity. |
322 | |
325 | |
323 | =back |
326 | =back |
324 | |
327 | |
325 | =head2 SPEED |
328 | =head2 SPEED |
|
|
329 | |
|
|
330 | It seems that JSON::XS is surprisingly fast, as shown in the following |
|
|
331 | tables. They have been generated with the help of the C<eg/bench> program |
|
|
332 | in the JSON::XS distribution, to make it easy to compare on your own |
|
|
333 | system. |
|
|
334 | |
|
|
335 | First is a comparison between various modules using a very simple JSON |
|
|
336 | string, showing the number of encodes/decodes per second (JSON::XS is |
|
|
337 | the functional interface, while JSON::XS/2 is the OO interface with |
|
|
338 | pretty-printing and hashkey sorting enabled). |
|
|
339 | |
|
|
340 | module | encode | decode | |
|
|
341 | -----------|------------|------------| |
|
|
342 | JSON | 14006 | 6820 | |
|
|
343 | JSON::DWIW | 200937 | 120386 | |
|
|
344 | JSON::PC | 85065 | 129366 | |
|
|
345 | JSON::Syck | 59898 | 44232 | |
|
|
346 | JSON::XS | 1171478 | 342435 | |
|
|
347 | JSON::XS/2 | 730760 | 328714 | |
|
|
348 | -----------+------------+------------+ |
|
|
349 | |
|
|
350 | That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80 |
|
|
351 | times faster than JSON, even with pretty-printing and key sorting. |
|
|
352 | |
|
|
353 | Using a longer test string (roughly 8KB, generated from Yahoo! Locals |
|
|
354 | search API (http://nanoref.com/yahooapis/mgPdGg): |
|
|
355 | |
|
|
356 | module | encode | decode | |
|
|
357 | -----------|------------|------------| |
|
|
358 | JSON | 673 | 38 | |
|
|
359 | JSON::DWIW | 5271 | 770 | |
|
|
360 | JSON::PC | 9901 | 2491 | |
|
|
361 | JSON::Syck | 2360 | 786 | |
|
|
362 | JSON::XS | 37398 | 3202 | |
|
|
363 | JSON::XS/2 | 13765 | 3153 | |
|
|
364 | -----------+------------+------------+ |
|
|
365 | |
|
|
366 | Again, JSON::XS leads by far in the encoding case, while still beating |
|
|
367 | every other module in the decoding case. |
|
|
368 | |
|
|
369 | Last example is an almost 8MB large hash with many large binary values |
|
|
370 | (PNG files), resulting in a lot of escaping: |
|
|
371 | |
|
|
372 | =head1 BUGS |
|
|
373 | |
|
|
374 | While the goal of this module is to be correct, that unfortunately does |
|
|
375 | not mean its bug-free, only that I think its design is bug-free. It is |
|
|
376 | still very young and not well-tested. If you keep reporting bugs they will |
|
|
377 | be fixed swiftly, though. |
326 | |
378 | |
327 | =cut |
379 | =cut |
328 | |
380 | |
329 | 1; |
381 | 1; |
330 | |
382 | |