… | |
… | |
86 | package JSON::XS; |
86 | package JSON::XS; |
87 | |
87 | |
88 | use strict; |
88 | use strict; |
89 | |
89 | |
90 | BEGIN { |
90 | BEGIN { |
91 | our $VERSION = '1.2'; |
91 | our $VERSION = '1.23'; |
92 | our @ISA = qw(Exporter); |
92 | our @ISA = qw(Exporter); |
93 | |
93 | |
94 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
94 | our @EXPORT = qw(to_json from_json objToJson jsonToObj); |
95 | require Exporter; |
95 | require Exporter; |
96 | |
96 | |
… | |
… | |
612 | It seems that JSON::XS is surprisingly fast, as shown in the following |
612 | It seems that JSON::XS is surprisingly fast, as shown in the following |
613 | tables. They have been generated with the help of the C<eg/bench> program |
613 | tables. They have been generated with the help of the C<eg/bench> program |
614 | in the JSON::XS distribution, to make it easy to compare on your own |
614 | in the JSON::XS distribution, to make it easy to compare on your own |
615 | system. |
615 | system. |
616 | |
616 | |
617 | First comes a comparison between various modules using a very short JSON |
617 | First comes a comparison between various modules using a very short |
618 | string: |
618 | single-line JSON string: |
619 | |
619 | |
620 | {"method": "handleMessage", "params": ["user1", "we were just talking"], "id": null} |
620 | {"method": "handleMessage", "params": ["user1", "we were just talking"], \ |
|
|
621 | "id": null, "array":[1,11,234,-5,1e5,1e7, true, false]} |
621 | |
622 | |
622 | It shows the number of encodes/decodes per second (JSON::XS uses the |
623 | It shows the number of encodes/decodes per second (JSON::XS uses the |
623 | functional interface, while JSON::XS/2 uses the OO interface with |
624 | functional interface, while JSON::XS/2 uses the OO interface with |
624 | pretty-printing and hashkey sorting enabled). Higher is better: |
625 | pretty-printing and hashkey sorting enabled). Higher is better: |
625 | |
626 | |
626 | module | encode | decode | |
627 | module | encode | decode | |
627 | -----------|------------|------------| |
628 | -----------|------------|------------| |
628 | JSON | 11488.516 | 7823.035 | |
629 | JSON | 7645.468 | 4208.613 | |
629 | JSON::DWIW | 94708.054 | 129094.260 | |
630 | JSON::DWIW | 68534.379 | 79437.576 | |
630 | JSON::PC | 63884.157 | 128528.212 | |
631 | JSON::PC | 65948.176 | 78251.940 | |
631 | JSON::Syck | 34898.677 | 42096.911 | |
632 | JSON::Syck | 23379.621 | 28416.694 | |
632 | JSON::XS | 654027.064 | 396423.669 | |
633 | JSON::XS | 388361.481 | 199728.762 | |
633 | JSON::XS/2 | 371564.190 | 371725.613 | |
634 | JSON::XS/2 | 218453.333 | 192399.266 | |
|
|
635 | JSON::XS/3 | 338250.323 | 192399.266 | |
|
|
636 | Storable | 15732.573 | 28571.553 | |
634 | -----------+------------+------------+ |
637 | -----------+------------+------------+ |
635 | |
638 | |
636 | That is, JSON::XS is more than six times faster than JSON::DWIW on |
639 | That is, JSON::XS is about five times faster than JSON::DWIW on encoding, |
637 | encoding, more than three times faster on decoding, and about thirty times |
640 | about three times faster on decoding, and over fourty times faster |
638 | faster than JSON, even with pretty-printing and key sorting. |
641 | than JSON, even with pretty-printing and key sorting. It also compares |
|
|
642 | favourably to Storable for small amounts of data. |
639 | |
643 | |
640 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
644 | Using a longer test string (roughly 18KB, generated from Yahoo! Locals |
641 | search API (http://nanoref.com/yahooapis/mgPdGg): |
645 | search API (http://nanoref.com/yahooapis/mgPdGg): |
642 | |
646 | |
643 | module | encode | decode | |
647 | module | encode | decode | |
644 | -----------|------------|------------| |
648 | -----------|------------|------------| |
645 | JSON | 273.023 | 44.674 | |
649 | JSON | 254.685 | 37.665 | |
646 | JSON::DWIW | 1089.383 | 1145.704 | |
650 | JSON::DWIW | 1014.244 | 1087.678 | |
647 | JSON::PC | 3097.419 | 2393.921 | |
651 | JSON::PC | 3602.116 | 2307.352 | |
648 | JSON::Syck | 514.060 | 843.053 | |
652 | JSON::Syck | 558.035 | 776.263 | |
649 | JSON::XS | 6479.668 | 3636.364 | |
653 | JSON::XS | 5747.196 | 3543.684 | |
650 | JSON::XS/2 | 3774.221 | 3599.124 | |
654 | JSON::XS/2 | 3968.121 | 3589.170 | |
|
|
655 | JSON::XS/3 | 6105.246 | 3561.134 | |
|
|
656 | Storable | 4456.337 | 5320.020 | |
651 | -----------+------------+------------+ |
657 | -----------+------------+------------+ |
652 | |
658 | |
653 | Again, JSON::XS leads by far. |
659 | Again, JSON::XS leads by far. |
654 | |
660 | |
655 | On large strings containing lots of high unicode characters, some modules |
661 | On large strings containing lots of high unicode characters, some modules |