Description of the scene:
This article only validates the use of the JSON key as the parsing speed of the deserialization condition in an Android environment . The conclusion is that the fastest resolution is not Ali's Fastjson, not Google's Gson, but Json-smart.
Android 4.4.2
Fastjson-1.1.34.android.jar
Gson-2.2.4.jar
Json-smart-2.0-rc3.jar
* * Note the conditions of the scene * *
Core code:
Package Com.h3c.mytestview;import Java.io.stringreader;import Net.minidev.json.jsonvalue;import Android.app.activity;import Android.os.bundle;import Android.util.log;import Com.alibaba.fastjson.json;import Com.alibaba.fastjson.jsonobject;import Com.google.gson.gson;import Com.google.gson.jsonelement;import Com.google.gson.jsonobject;import Com.google.gson.jsonparser;import Com.google.gson.stream.jsonreader;public Class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.on Create (savedinstancestate); Setcontentview (R.layout.activity_main); New Thread (New Runnable () {@Override public void run () {dosth (); }}). Start (); } private void Dosth () {LOG.E ("h6c", "Start ..."); String json = "{\" name\ ": \" Reiz\ "}"; String k = ""; try {Long startTime1 = System.currenttimemillis (); for (int n = 0;n <100000; n++) {Org.json.JSONObject Jo; Jo = new Org.json.JSONObject (JSON); K = jo.getstring ("name"); } Long endTime1 = System.currenttimemillis ()-startTime1; LOG.E ("h6c", "Android:" + endTime1); Long startTime2 = System.currenttimemillis (); for (int n = 0;n < 100000; n++) {Jsonobject Jo = Json.parseobject (JSON); K = jo.getstring ("name"); } Long endTime2 = System.currenttimemillis ()-startTime2; LOG.E ("h6c", "Fastjson:" + endTime2); Long StartTime3 = System.currenttimemillis (); for (int n = 0;n < 100000; n++) {Net.minidev.json.JSONObject Jo = (net.minidev.json.JSONObject) jsonvalue . Parsestrict (JSON); K = (String) jo.get ("name"); } Long EndTime3 = System.currenttimemillis ()-StartTime3; LOG.E ("h6c", "Json-smart:" +ENDTIME3); Long startTime4 = System.currenttimemillis (); for (int n = 0;n < 100000; n++) {Jsonelement JE = new Jsonparser (). Parse (JSON); Jsonobject Jo = Je.getasjsonobject (); K = Jo.get ("name"). Getasstring (); } Long EndTime4 = System.currenttimemillis ()-startTime4; LOG.E ("h6c", "Gson:" +endtime4); } catch (Exception e) {e.printstacktrace (); } }}
Test results:
Galaxy S3
===========galaxy s3=============105-22 11:04:17.120:e/h6c (28681): Start ... 05-22 11:04:21.525:e/h6c (28681): Android:440005-22 11:04:28.135:e/h6c (28681): Fastjson:660805-22 11:04:31.600:e/h6c (28681): Json-smart:346705-22 11:04:47.440:e/h6c (28681): Gson:15839===========galaxy S3=============205-22 11:05:08.230:E/H6C (28681): Start ... 05-22 11:05:12.120:e/h6c (28681): Android:388605-22 11:05:17.285:e/h6c (28681): Fastjson:516705-22 11:05:21.020:e/h6c (28681): Json-smart:373605-22 11:05:34.040:e/h6c (28681): Gson:13018===========galaxy S3=============305-22 11:05:45.440:E/H6C (28681): Start ... 05-22 11:05:49.470:e/h6c (28681): Android:403305-22 11:05:54.500:e/h6c (28681): Fastjson:503105-22 11:05:58.240:e/h6c (28681): Json-smart:373605-22 11:06:13.485:e/h6c (28681): gson:15245
Galaxy S4
===========galaxy s4=============105-22 10:58:03.541:e/h6c (26600): Start ... 05-22 10:58:06.934:e/h6c (26600): Android:339305-22 10:58:12.680:e/h6c (26600): Fastjson:575205-22 10:58:15.232:e/h6c (26600): Json-smart:254905-22 10:58:24.841:e/h6c (26600): Gson:9610===========galaxy s4=============205-22 11:00:51.675:E/H6C (26600): Start ... 05-22 11:00:54.878:e/h6c (26600): Android:320905-22 11:01:00.413:e/h6c (26600): Fastjson:552605-22 11:01:02.986:e/h6c (26600): Json-smart:256905-22 11:01:11.084:e/h6c (26600): Gson:8099===========galaxy s4=============305-22 11:01:31.213:E/H6C (26600): Start ... 05-22 11:01:34.717:e/h6c (26600): Android:350805-22 11:01:40.172:e/h6c (26600): Fastjson:544305-22 11:01:42.734:e/h6c (26600): Json-smart:256605-22 11:01:52.554:e/h6c (26600): gson:9823
Xiaomi3
===========xiaomi 3=============105-22 11:02:05.461:e/h6c (30473): Start ... 05-22 11:02:08.021:e/h6c (30473): Android:256105-22 11:02:11.781:e/h6c (30473): Fastjson:376605-22 11:02:13.411:e/h6c (30473): Json-smart:162905-22 11:02:16.811:e/h6c (30473): Gson:3402===========xiaomi 3=============205-22 11:02:30.291:E/H6C (30473): Start ... 05-22 11:02:32.481:e/h6c (30473): Android:218405-22 11:02:36.341:e/h6c (30473): Fastjson:385605-22 11:02:37.781:e/h6c (30473): Json-smart:143905-22 11:02:40.991:e/h6c (30473): Gson:3210===========xiaomi 3=============305-22 11:02:47.731:E/H6C (30473): Start ... 05-22 11:02:50.271:e/h6c (30473): Android:254805-22 11:02:53.831:e/h6c (30473): Fastjson:355305-22 11:02:55.261:e/h6c (30473): Json-smart:143105-22 11:02:58.571:e/h6c (30473): gson:3310
Judging from the test results:
In the case of using key to parse JSON, the fastest is Json-smart, and its parsing speed has improved.
The conclusion of this paper is that Android native Java parsing already has the basic JSON parsing capability and has some advantages in speed, so it is not necessary to cite the larger Fastjson and Gson in simple scenes. And in the case of no extreme pursuit of speed without introducing Json-smart, because it may only help you to save the background 1s of time, the sense of the fact that the perception is not obvious.