Open zhangjiepeng opened 4 years ago
Hey, first some comments :)
If the speed difference persists, this is indeed worrying. 1340ms is more than a second!
I also tried a small benchmark with 10k conversions like @zhangjiepeng did for warmup and then 10k conversions where I measured the average duration. Results varied of course, but this was a typical result:
Average duration with GSON: 0.0389ms
Average duration with Klaxon: 0.2669ms
Average duration with Klaxon() instantiated once: 0.1308ms
So the instantiation of the Klaxon object takes half of the parsing time. But still, Gson is an order of magnitude faster.
var p = Person().apply { name = "h"; age = 10 } var start = System.currentTimeMillis() var gson = Gson() var psg = gson.toJson(p) var p1 = gson.fromJson(psg,Person::class.java)
textView.setText("gson cost:"+(System.currentTimeMillis() - start))
gson cost:10 klaxon cost: 1340