… | |
… | |
78 | =cut |
78 | =cut |
79 | |
79 | |
80 | package JSON::XS; |
80 | package JSON::XS; |
81 | |
81 | |
82 | BEGIN { |
82 | BEGIN { |
83 | $VERSION = '0.31'; |
83 | $VERSION = '0.5'; |
84 | @ISA = qw(Exporter); |
84 | @ISA = qw(Exporter); |
85 | |
85 | |
86 | @EXPORT = qw(to_json from_json); |
86 | @EXPORT = qw(to_json from_json); |
87 | require Exporter; |
87 | require Exporter; |
88 | |
88 | |
… | |
… | |
527 | tables. They have been generated with the help of the C<eg/bench> program |
527 | tables. They have been generated with the help of the C<eg/bench> program |
528 | in the JSON::XS distribution, to make it easy to compare on your own |
528 | in the JSON::XS distribution, to make it easy to compare on your own |
529 | system. |
529 | system. |
530 | |
530 | |
531 | First comes a comparison between various modules using a very short JSON |
531 | First comes a comparison between various modules using a very short JSON |
532 | string (83 bytes), showing the number of encodes/decodes per second |
532 | string: |
533 | (JSON::XS is the functional interface, while JSON::XS/2 is the OO |
533 | |
|
|
534 | {"method": "handleMessage", "params": ["user1", "we were just talking"], "id": null} |
|
|
535 | |
|
|
536 | It shows the number of encodes/decodes per second (JSON::XS uses the |
|
|
537 | functional interface, while JSON::XS/2 uses the OO interface with |
534 | interface with pretty-printing and hashkey sorting enabled). Higher is |
538 | pretty-printing and hashkey sorting enabled). Higher is better: |
535 | better: |
|
|
536 | |
539 | |
537 | module | encode | decode | |
540 | module | encode | decode | |
538 | -----------|------------|------------| |
541 | -----------|------------|------------| |
539 | JSON | 14006 | 6820 | |
542 | JSON | 11488.516 | 7823.035 | |
540 | JSON::DWIW | 200937 | 120386 | |
543 | JSON::DWIW | 94708.054 | 129094.260 | |
541 | JSON::PC | 85065 | 129366 | |
544 | JSON::PC | 63884.157 | 128528.212 | |
542 | JSON::Syck | 59898 | 44232 | |
545 | JSON::Syck | 34898.677 | 42096.911 | |
543 | JSON::XS | 1171478 | 342435 | |
546 | JSON::XS | 654027.064 | 396423.669 | |
544 | JSON::XS/2 | 730760 | 328714 | |
547 | JSON::XS/2 | 371564.190 | 371725.613 | |
545 | -----------+------------+------------+ |
548 | -----------+------------+------------+ |
546 | |
549 | |
547 | That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80 |
550 | That is, JSON::XS is more than six times faster than JSON::DWIW on |
|
|
551 | encoding, more than three times faster on decoding, and about thirty times |
548 | times faster than JSON, even with pretty-printing and key sorting. |
552 | faster than JSON, even with pretty-printing and key sorting. |
549 | |
553 | |
550 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
554 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
551 | search API (http://nanoref.com/yahooapis/mgPdGg): |
555 | search API (http://nanoref.com/yahooapis/mgPdGg): |
552 | |
556 | |
553 | module | encode | decode | |
557 | module | encode | decode | |
554 | -----------|------------|------------| |
558 | -----------|------------|------------| |
555 | JSON | 673 | 38 | |
559 | JSON | 273.023 | 44.674 | |
556 | JSON::DWIW | 5271 | 770 | |
560 | JSON::DWIW | 1089.383 | 1145.704 | |
557 | JSON::PC | 9901 | 2491 | |
561 | JSON::PC | 3097.419 | 2393.921 | |
558 | JSON::Syck | 2360 | 786 | |
562 | JSON::Syck | 514.060 | 843.053 | |
559 | JSON::XS | 37398 | 3202 | |
563 | JSON::XS | 6479.668 | 3636.364 | |
560 | JSON::XS/2 | 13765 | 3153 | |
564 | JSON::XS/2 | 3774.221 | 3599.124 | |
561 | -----------+------------+------------+ |
565 | -----------+------------+------------+ |
562 | |
566 | |
563 | Again, JSON::XS leads by far in the encoding case, while still beating |
567 | Again, JSON::XS leads by far. |
564 | every other module in the decoding case. |
|
|
565 | |
568 | |
566 | On large strings containing lots of unicode characters, some modules |
569 | On large strings containing lots of high unicode characters, some modules |
567 | (such as JSON::PC) decode faster than JSON::XS, but the result will be |
570 | (such as JSON::PC) seem to decode faster than JSON::XS, but the result |
568 | broken due to missing unicode handling. Others refuse to decode or encode |
571 | will be broken due to missing (or wrong) unicode handling. Others refuse |
569 | properly, so it was impossible to prepare a fair comparison table for that |
572 | to decode or encode properly, so it was impossible to prepare a fair |
570 | case. |
573 | comparison table for that case. |
571 | |
574 | |
572 | =head1 RESOURCE LIMITS |
575 | =head1 RESOURCE LIMITS |
573 | |
576 | |
574 | JSON::XS does not impose any limits on the size of JSON texts or Perl |
577 | JSON::XS does not impose any limits on the size of JSON texts or Perl |
575 | values they represent - if your machine can handle it, JSON::XS will |
578 | values they represent - if your machine can handle it, JSON::XS will |