JSON parsing performance comparison (Gson and Jackson) (ZZ)

Source: Internet
Author: User

JSON now has a lot of third-party parsing work, such as Json-lib,gson,jackson,fastjson and so on. When we complete the general json-object conversion work, there is almost no problem.
But when the amount of data comes up, what about their performance geometry? I set out to test the Gson and Jackson, others such as json-lib performance is poor, Fastjson although the performance is very good, but there are some problems in the use, so there is no test.

Abbreviated code:
//Generate a larger JSON
list list = new ArrayList ();
for (int i = 0; i < 500000; i++) {
Jsonobject obj = new Jsonobject ();
Obj.setid (i);
obj.setname ("name" + string.valueof (i));
list.add (obj);
        }

Gson Gson = new Gsonbuilder (). Create ();
String str = gson.tojson (list);

//1,gson parsing
Long Start1 = System.currenttimemillis ();
List L = Gson.fromjson (str, new TypeToken <> > () {
}.gettype ());
System.out.println ("Gson Time Elapse:" + (System.currenttimemillis ()-Start1));
System.out.println (L.size ());

//2,jackson parsing
Objectmapper mapper = new Objectmapper ();
Long Start2 = System.currenttimemillis ();
List L2 = Mapper.readvalue (str, new typereference <> > () {
        });
System.out.println ("Jackson Time Elapse:" + (System.currenttimemillis ()-Start2));
System.out.println (L2.size ());

Test Results:

Data set Gson time-consuming Jackson time-consuming

10w            1366                    138

20w            2720                    165

30w            4706                    332

40w            9526                    317

50w Native Oom 363


from the test results, Jackson's performance was almost 10 times times the Gson, and as the data grew, Jackson's time was steady, and Gson's time-consuming growth was significant, and the final direct Oom
As for why Jackson has such a good performance, I have no scrutiny, probably because Jackson uses streaming.
Source: http://blog.itpub.net/28912557/viewspace-1267965/

From for notes (Wiz)

JSON parsing performance comparison (Gson and Jackson) (ZZ)

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.