… | |
… | |
507 | It seems that JSON::XS is surprisingly fast, as shown in the following |
507 | It seems that JSON::XS is surprisingly fast, as shown in the following |
508 | tables. They have been generated with the help of the C<eg/bench> program |
508 | tables. They have been generated with the help of the C<eg/bench> program |
509 | in the JSON::XS distribution, to make it easy to compare on your own |
509 | in the JSON::XS distribution, to make it easy to compare on your own |
510 | system. |
510 | system. |
511 | |
511 | |
512 | First is a comparison between various modules using a very simple JSON |
512 | First comes a comparison between various modules using a very short JSON |
513 | string, showing the number of encodes/decodes per second (JSON::XS is |
513 | string (83 bytes), showing the number of encodes/decodes per second |
514 | the functional interface, while JSON::XS/2 is the OO interface with |
514 | (JSON::XS is the functional interface, while JSON::XS/2 is the OO |
515 | pretty-printing and hashkey sorting enabled). |
515 | interface with pretty-printing and hashkey sorting enabled). Higher is |
|
|
516 | better: |
516 | |
517 | |
517 | module | encode | decode | |
518 | module | encode | decode | |
518 | -----------|------------|------------| |
519 | -----------|------------|------------| |
519 | JSON | 14006 | 6820 | |
520 | JSON | 14006 | 6820 | |
520 | JSON::DWIW | 200937 | 120386 | |
521 | JSON::DWIW | 200937 | 120386 | |
… | |
… | |
525 | -----------+------------+------------+ |
526 | -----------+------------+------------+ |
526 | |
527 | |
527 | That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80 |
528 | That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80 |
528 | times faster than JSON, even with pretty-printing and key sorting. |
529 | times faster than JSON, even with pretty-printing and key sorting. |
529 | |
530 | |
530 | Using a longer test string (roughly 8KB, generated from Yahoo! Locals |
531 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
531 | search API (http://nanoref.com/yahooapis/mgPdGg): |
532 | search API (http://nanoref.com/yahooapis/mgPdGg): |
532 | |
533 | |
533 | module | encode | decode | |
534 | module | encode | decode | |
534 | -----------|------------|------------| |
535 | -----------|------------|------------| |
535 | JSON | 673 | 38 | |
536 | JSON | 673 | 38 | |
… | |
… | |
541 | -----------+------------+------------+ |
542 | -----------+------------+------------+ |
542 | |
543 | |
543 | Again, JSON::XS leads by far in the encoding case, while still beating |
544 | Again, JSON::XS leads by far in the encoding case, while still beating |
544 | every other module in the decoding case. |
545 | every other module in the decoding case. |
545 | |
546 | |
|
|
547 | On large strings containing lots of unicode characters, some modules |
|
|
548 | (such as JSON::PC) decode faster than JSON::XS, but the result will be |
|
|
549 | broken due to missing unicode handling. Others refuse to decode or encode |
|
|
550 | properly, so it was impossible to prepare a fair comparison table for that |
|
|
551 | case. |
|
|
552 | |
546 | =head1 RESOURCE LIMITS |
553 | =head1 RESOURCE LIMITS |
547 | |
554 | |
548 | JSON::XS does not impose any limits on the size of JSON texts or Perl |
555 | JSON::XS does not impose any limits on the size of JSON texts or Perl |
549 | values they represent - if your machine can handle it, JSON::XS will |
556 | values they represent - if your machine can handle it, JSON::XS will |
550 | encode or decode it. Future versions might optionally impose structure |
557 | encode or decode it. Future versions might optionally impose structure |