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