JSON serialization is now very much used, especially in the case of a front-end separation, most of the common C # Under the use of Newtonsoft.json to operate, a small amount of cases, but also can be ignored, but the large amount of case to consider the use of Servicestack.text to operate, the serialization performance is similar, the deserialization performance is about one times higher
intCount =10000; User User=NewUser () {Id =1, Name ="Tyh", Addtime = DateTime.Now, age = the, Status =true };stringtemp =String.Empty; User User1=NewUser ();stringTemp1 ="{\ "id\": \ "2\", \ "name\": \ "xxc\", \ "addtime\": \ "2016-09-07 10:10:10\", \ "age\": \ "15\", \ "status\": \ "true\"}"; Stopwatch SW=NewStopwatch (); SW. Restart (); for(inti =0; I < count; i++) {Temp=ServiceStack.Text.JsonSerializer.SerializeToString (user);} Sw. Stop (); Response.Write ("Servicestack-ser:"+ SW. Elapsedmilliseconds +"</br>"); SW. Restart (); for(inti =0; I < count; i++) {User1= servicestack.text.jsonserializer.deserializefromstring<user>(TEMP1);} Sw. Stop (); Response.Write ("Servicestack-des:"+ SW. Elapsedmilliseconds +"</br>"); SW. Restart (); for(inti =0; I < count; i++) {Temp=Newtonsoft.Json.JsonConvert.SerializeObject (user);} Sw. Stop (); Response.Write ("Newtonsoft-ser:"+ SW. Elapsedmilliseconds +"</br>"); SW. Restart (); for(inti =0; I < count; i++) {User1= newtonsoft.json.jsonconvert.deserializeobject<user>(TEMP1);} Sw. Stop (); Response.Write ("Newtonsoft-des:"+ SW. Elapsedmilliseconds +"</br>"); Response.End ();
Here is the test results, I only cut one diagram, other self-test it
Servicestack.text/newtonsoft.json of two Json serialization performance comparisons