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.17 by root, Sat Mar 24 19:42:14 2007 UTC vs.
Revision 1.20 by root, Sun Mar 25 00:47:42 2007 UTC

77 77
78=cut 78=cut
79 79
80package JSON::XS; 80package JSON::XS;
81 81
82use strict;
83
82BEGIN { 84BEGIN {
83 $VERSION = '0.5'; 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}
527tables. They have been generated with the help of the C<eg/bench> program 529tables. They have been generated with the help of the C<eg/bench> program
528in the JSON::XS distribution, to make it easy to compare on your own 530in the JSON::XS distribution, to make it easy to compare on your own
529system. 531system.
530 532
531First comes a comparison between various modules using a very short JSON 533First comes a comparison between various modules using a very short JSON
532string (83 bytes), showing the number of encodes/decodes per second 534string:
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
538It shows the number of encodes/decodes per second (JSON::XS uses the
539functional interface, while JSON::XS/2 uses the OO interface with
534interface with pretty-printing and hashkey sorting enabled). Higher is 540pretty-printing and hashkey sorting enabled). Higher is better:
535better:
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
547That is, JSON::XS is 6 times faster than than JSON::DWIW and about 80 552That is, JSON::XS is more than six times faster than JSON::DWIW on
553encoding, more than three times faster on decoding, and about thirty times
548times faster than JSON, even with pretty-printing and key sorting. 554faster than JSON, even with pretty-printing and key sorting.
549 555
550Using a longer test string (roughly 18KB, generated from Yahoo! Locals 556Using a longer test string (roughly 18KB, generated from Yahoo! Locals
551search API (http://nanoref.com/yahooapis/mgPdGg): 557search 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
563Again, JSON::XS leads by far in the encoding case, while still beating 569Again, JSON::XS leads by far.
564every other module in the decoding case.
565 570
566On large strings containing lots of unicode characters, some modules 571On 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
568broken due to missing unicode handling. Others refuse to decode or encode 573will be broken due to missing (or wrong) unicode handling. Others refuse
569properly, so it was impossible to prepare a fair comparison table for that 574to decode or encode properly, so it was impossible to prepare a fair
570case. 575comparison table for that case.
571 576
572=head1 RESOURCE LIMITS 577=head1 RESOURCE LIMITS
573 578
574JSON::XS does not impose any limits on the size of JSON texts or Perl 579JSON::XS does not impose any limits on the size of JSON texts or Perl
575values they represent - if your machine can handle it, JSON::XS will 580values they represent - if your machine can handle it, JSON::XS will

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines