ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/JSON-XS/XS.pm
(Generate patch)

Comparing JSON-XS/XS.pm (file contents):
Revision 1.3 by root, Thu Mar 22 18:10:29 2007 UTC vs.
Revision 1.5 by root, Thu Mar 22 21:36:52 2007 UTC

242=head1 COMPARISON 242=head1 COMPARISON
243 243
244As already mentioned, this module was created because none of the existing 244As already mentioned, this module was created because none of the existing
245JSON modules could be made to work correctly. First I will describe the 245JSON modules could be made to work correctly. First I will describe the
246problems (or pleasures) I encountered with various existing JSON modules, 246problems (or pleasures) I encountered with various existing JSON modules,
247followed by some benchmark values. 247followed by some benchmark values. JSON::XS was designed not to suffer
248from any of these problems or limitations.
248 249
249=over 4 250=over 4
250 251
251=item JSON 252=item JSON 1.07
252 253
253Slow (but very portable, as it is written in pure Perl). 254Slow (but very portable, as it is written in pure Perl).
254 255
255Undocumented/buggy Unicode handling (how JSON handles unicode values is 256Undocumented/buggy Unicode handling (how JSON handles unicode values is
256undocumented. One can get far by feeding it unicode strings and doing 257undocumented. One can get far by feeding it unicode strings and doing
258 259
259No roundtripping (strings get clobbered if they look like numbers, e.g. 260No roundtripping (strings get clobbered if they look like numbers, e.g.
260the string C<2.0> will encode to C<2.0> instead of C<"2.0">, and that will 261the string C<2.0> will encode to C<2.0> instead of C<"2.0">, and that will
261decode into the number 2. 262decode into the number 2.
262 263
263=item JSON::PC 264=item JSON::PC 0.01
264 265
265Very fast. 266Very fast.
267
268Undocumented/buggy Unicode handling.
269
270No roundtripping.
271
272Has problems handling many Perl values (e.g. regex results and other magic
273values will make it croak).
274
275Does not even generate valid JSON (C<{1,2}> gets converted to C<{1:2}>
276which is not a valid JSON string.
277
278Unmaintained (maintainer unresponsive for many months, bugs are not
279getting fixed).
280
281=item JSON::Syck 0.21
282
283Very buggy (often crashes).
266 284
267Very inflexible (no human-readable format supported, format pretty much 285Very inflexible (no human-readable format supported, format pretty much
268undocumented. I need at least a format for easy reading by humans and a 286undocumented. I need at least a format for easy reading by humans and a
269single-line compact format for use in a protocol, and preferably a way to 287single-line compact format for use in a protocol, and preferably a way to
270generate ASCII-only JSON strings). 288generate ASCII-only JSON strings).
271
272Undocumented/buggy Unicode handling.
273
274No roundtripping.
275
276Has problems handling many Perl values.
277
278Does not even generate valid JSON (C<{1,2}> gets converted to C<{1:2}>
279which is not a valid JSON string.
280
281Unmaintained (maintainer unresponsive for many months, bugs are not
282getting fixed).
283
284=item JSON::Syck
285
286Very buggy (often crashes).
287
288Very inflexible.
289 289
290Completely broken (and confusingly documented) Unicode handling (unicode 290Completely broken (and confusingly documented) Unicode handling (unicode
291escapes are not working properly, you need to set ImplicitUnicode to 291escapes are not working properly, you need to set ImplicitUnicode to
292I<different> values on en- and decoding to get symmetric behaviour). 292I<different> values on en- and decoding to get symmetric behaviour).
293 293
305JSON. One bank might parse a given non-JSON request and deduct money, 305JSON. One bank might parse a given non-JSON request and deduct money,
306while the other might reject the transaction with a syntax error. While a 306while the other might reject the transaction with a syntax error. While a
307good protocol will at least recover, that is extra unnecessary work and 307good protocol will at least recover, that is extra unnecessary work and
308the transaction will still not succeed). 308the transaction will still not succeed).
309 309
310=item JSON::DWIW 310=item JSON::DWIW 0.04
311 311
312Very fast. Very natural. Very nice. 312Very fast. Very natural. Very nice.
313 313
314Undocumented unicode handling (but the best of the pack. Unicode escapes 314Undocumented unicode handling (but the best of the pack. Unicode escapes
315still don't get parsed properly). 315still don't get parsed properly).
316 316
317Very inflexible. 317Very inflexible.
318 318
319No roundtripping. 319No roundtripping.
320 320
321Does not generate valid JSON (key strings are often unquoted, empty keys
322result in nothing being output)
323
321Does not check input for validity. 324Does not check input for validity.
322 325
323=back 326=back
324 327
325=head2 SPEED 328=head2 SPEED
329
330It seems that JSON::XS is surprisingly fast, as shown in the following
331tables. They have been generated with the help of the C<eg/bench> program
332in the JSON::XS distribution, to make it easy to compare on your own
333system.
334
335First is a comparison between various modules using a very simple JSON
336string, showing the number of encodes/decodes per second (JSON::XS is
337the functional interface, while JSON::XS/2 is the OO interface with
338pretty-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
350That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80
351times faster than JSON, even with pretty-printing and key sorting.
352
353Using a longer test string (roughly 8KB, generated from Yahoo! Locals
354search 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
366Again, JSON::XS leads by far in the encoding case, while still beating
367every other module in the decoding case.
368
369Last 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
374While the goal of this module is to be correct, that unfortunately does
375not mean its bug-free, only that I think its design is bug-free. It is
376still very young and not well-tested. If you keep reporting bugs they will
377be fixed swiftly, though.
326 378
327=cut 379=cut
328 380
3291; 3811;
330 382

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines