JSON class library performance comparison between Jackson and Json-lib [go]

Source: Internet
Author: User

jackson:http://jackson.codehaus.org/

json-lib:http://json-lib.sourceforge.net/

gson:http://code.google.com/p/google-gson/

Test environment:

1. Working computer: Intel Dual Core E8400 6GHz, Memory 4gb,winxp

2, Json-lib with the latest Jdk15,gson version is the latest V1.4,jackson is also the latest v1.5.5,jdk-v1.6.0_20,jmeter-v2.4

3, the test does not open any unrelated process, each completed a test after closing JMeter finishing memory, then the next test, each test run 3 times, averaging

4, JSON to Java bean meaning to convert JSON format to Java class, this class includes map, List, Date, Integer/long/double, string and other types of properties, Java Bean to JSON is the same. In addition, the two turn each other, the data of each conversion is randomly generated

Test Results:

* The higher the value of the throughput, the better, the lower the total time-consuming value, the better

JSON to bean,5 threads concurrently, about 200-byte objects, 10 million conversions:

Jackson Json-lib Gson
Tps 64113.7 8067.4 13952.8
Total time taken (seconds) 155 1238 700

The bean goes json,5 threads concurrently, about 200 bytes of objects, 10 million conversions:

Jackson Json-lib Gson
Tps 54802 15093.2 17308.2
Total time taken (seconds) 181 661 560

JSON to bean,5 threads concurrent, about 2K objects, 10 million conversions:

Jackson Json-lib Gson
Tps 37314 2406.9 3657.50
Total time taken (seconds) 267 4120 2720

Bean to json,5 threads concurrent, about 2K objects, 10 million conversions:

Jackson Json-lib Gson
Tps 30922.2 4274.8 4977.00
Total time taken (seconds) 322 2320 2000

Test Summary:

1 . Obviously, no matter what kind of conversion, Jackson > Gson > Json-lib.

Jackson's ability to deal with the json-lib is about 10 times times higher.

2, Json-lib seems to have stopped updating, the latest version is based on JDK15, and Jackson's community is more active;

3, While testing the performance, and the human flesh way to the three class library conversion correctness was checked , the three are up to 100% correct ;

4. Json-lib is cumbersome when converting a date type, as the following is the result of the conversion:

Json-lib:

{"Brithday": {"date": +, "Day": 2, "hours": 9, "minutes": +, "month": 7, "seconds": +, "time": 1282008266398, " Timezoneoffset ": -480," Year ": 110}}

Jackson:

{"Brithday": 1282008123101}

5, Json-lib dependentCommons series of packages and ezmorph pack of 5, and Jackson in addition to their own only rely on commons-logging
6. Jackson provides a complete node-based tree Model, as well as complete OJM data binding capabilities.

Jackson Use Example:

Jacksonmapper:

Created as a a hungry man singleton mode , Jackson used to convert the core class Objectmapper without having to new an object every time, a sentence on the official web: can reuse, share globally

Java code
  1. /**
  2. * @author Xuanyin
  3. *
  4. */
  5. Public class Jacksonmapper {
  6. /** 
  7. *
  8. */
  9. private Static final Objectmapper mapper = new Objectmapper ();
  10. /** 
  11. *
  12. */
  13. Private Jacksonmapper () {
  14. }
  15. /** 
  16. *
  17. * @return
  18. */
  19. public static Objectmapper getinstance () {
  20. return mapper;
  21. }
  22. }

JSON to Bean:

Java code
    1. ......
    2. String json = "...";
    3. Objectmapper mapper = Jacksonmapper.getinstance ();
    4. Yourbean bean = Mapper.readvalue (JSON, new Yourbean (). GetClass ());
    5. ......

Bean to JSON:

Java code
    1. ......
    2. Yourbean bean = new Yourbean ();
    3. ......
    4. Objectmapper mapper = Jacksonmapper.getinstance ();
    5. StringWriter SW = new StringWriter ();
    6. Jsongenerator Gen = New Jsonfactory (). Createjsongenerator (SW);
    7. Mapper.writevalue (gen, Bean);
    8. Gen.close ();
    9. String json = sw.tostring ();
    10. ......

* Yourbean of the above two pieces of code can of course be the basic type of Java

JSON class library performance comparison between Jackson and Json-lib [go]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.