Pratha-Shukla / google-gson

Automatically exported from code.google.com/p/google-gson
0 stars 0 forks source link

jsonparser performance #475

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

i have look with interest google-gson as a way to serialize complex java object 
to webapp.

now, i have to get the output back (json) and convert into a standard plain DOM 
object (or something like that) to be able to work with a generic json tree.

What i have done so far is to use a 
JsonReader reader = new JsonReader(in)
and then write a simple recursive function (taht is 90% equals to what you do 
when you use the jsonreader)
 to parse the three (do some peek, switch case, make it recursive and so on)

everything work like a charm, and is quite fast.

i have than take a look to json-smart v2 (newer ersion , used only as a parser, 
and is 20% fast than gson 2.2.2 (never version) parser

here are some example
gsonParser 5009ms
jsonSMART 3633ms

this is done with a huge json, iterated 20000 times x 10 repetition each (to 
allow a bit of warmup)
and this data are the avg except the first 2 iteration (leaved out to allow a 
warmup, useful for this kind of 
microbenckmark imho)

the json is a nested root -> 10 child -> 10 subchild each node with 10 random 
attr (mixed)

The code that create my custom "dom" element (that is for my convenience 
similar to dom4j syntax due to migration issue) is a wrapper for both library, 
then i use their internal obj to create my wrapper (creation costs is the same, 
the 2 method generate the same output)

Have you ever try some benchmarking with jsonSMART?
Obviusly gson is used to do other thinks, it's not only a parser for json, but 
in this case the save is pretty high.
I also haven't digg to much on jsonSMART, but probably it can make do work 
better, as in your case i don't use your jsonElement, but directly the parser 
(on jsonSMART i use their convenient jsonElement, since is so fast)

warm regards

Original issue reported on code.google.com by gippo...@gmail.com on 27 Sep 2012 at 1:29

GoogleCodeExporter commented 9 years ago
We rewrite the parser for the next release.
https://code.google.com/p/google-gson/source/detail?r=1184

Original comment by limpbizkit on 4 Feb 2013 at 3:30