机器人:GSON性能 [英] android: gson performance

查看:145
本文介绍了机器人:GSON性能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用GSON做我的对象映射在Android模拟器。

据处理JSON数据各地208 kb的时候是可笑缓慢。我没有任何等级制度在我的JSON。

对象映射完成后,我可以看到它的GSON约500记录创建。

有服用超过3分钟的Andr​​oid模拟器来映射输入JSON。

我已经注明我的实体包括字符串和情侣花车的。

这是我失去了一些东西?

任何想法,最佳实践将极大地帮助。

是否有快速的任何方式对象映射JSON数据?

  URL myURL =新的网址(URL);
        / *打开到URL的连接。 * /
        URLConnection的UCON = myURL.openConnection();
        / *
         *定义InputStreams从URLConnection的阅读。
         * /
        InputStream的是= ucon.getInputStream();
        InputStreamReader的读者=新InputStreamReader的(是);
        长计时单位计数= System.currentTimeMillis的();
        政策[]政策=新GSON()fromJson(读卡器,政策[]类。)。
        长endCount = System.currentTimeMillis的() - 计时单位计数;
        Log.d(时间到拉策略毫秒,+ endCount);
 

解决方案

我已经看到了这样的问题时,先上来,一般的共识是,杰克逊比GSON快得多。更多信息请参见以下链接:

  • <一个href="http://stackoverflow.com/questions/2378402/jackson-vs-gson">http://stackoverflow.com/questions/2378402/jackson-vs-gson
  • <一个href="http://stackoverflow.com/questions/2502807/replace-standard-android-json-parser-for-better-performance">http://stackoverflow.com/questions/2502807/replace-standard-android-json-parser-for-better-performance
  • <一个href="http://www.cowtown$c$cr.com/blog/archives/2009/12/entry_345.html">http://www.cowtown$c$cr.com/blog/archives/2009/12/entry_345.html
  • <一个href="http://stackoverflow.com/questions/338586/a-better-java-json-library">http://stackoverflow.com/questions/338586/a-better-java-json-library

下面是其中一个专门讨论Android版本: http://ubikapps.net/?p=525

I am trying to use gson to do my object mapping on the android emulator.

It has been ridiculously slow when processing json data around 208 kb. I do not have any hierarchies in my json.

After the object mapping is done, i can see it that gson created around 500 records.

It is taking it over 3 minutes on the android emulator to map the input json.

I have annotated my entity which comprises of strings and couple of floats.

An I missing something?

Any ideas, best practices would greatly help.

Are there any ways of quickly object mapping the json data?

        URL myURL = new URL(url);
        /* Open a connection to that URL. */
        URLConnection ucon = myURL.openConnection();
        /*
         * Define InputStreams to read from the URLConnection.
         */
        InputStream is = ucon.getInputStream();
        InputStreamReader reader = new InputStreamReader(is);
        long tickCount = System.currentTimeMillis();
        Policy[] policies = new Gson().fromJson(reader, Policy[].class);
        long endCount = System.currentTimeMillis() - tickCount;
        Log.d("Time to pull policies in milliseconds", "" + endCount);

解决方案

I've seen questions like this come up before, and the general consensus is that Jackson is much faster than Gson. See the following links for more information:

Here is one which specifically discusses Android: http://ubikapps.net/?p=525

这篇关于机器人:GSON性能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆