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)