使用 Dalvik VM 进行快速字符串比较?
我正在 Android 中使用 SAXParser 解析一个大的 XML 文件,想知道是否有更快的方法来进行字符串比较?我听说有传言说你可以使用 Dalvik VM 来做一些事情,这将节省分配的内存,从而加快速度,但我在网上找不到任何东西。
谁能给我指出正确的方向,要么使用 Dalvik 来加速我的解析,要么使用更好、更快的方法进行 XML 解析?
I'm parsing a big XML file using SAXParser in Android and was wondering if there's a faster way of doing string comparisons? I've heard rumours that you can use the Dalvik VM to do something which will save memory allocated and hence speed it all up, but I can't find anything online.
Can anyone point me in the right direction to either use Dalvik to speed up my parsing or a better, faster way of doing XML parsing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
String 的compareTo() 方法在dalvik 内部实现为特殊的手工汇编例程。您不太可能在字符串比较方面击败它的性能。
如果您正在下载的是 xml 文件,我不知道有什么方法可以加快您的解析时间。但是,如果你可以将它作为资源包含在apk中(在res/xml文件夹中),那么当你构建apk时,它会被编译成Android的二进制xml格式,并且你可以通过XmlResourceParser访问它,这应该显着快点
String's compareTo() method is implemented internally in dalvik as a special hand-crafted assembly routine. It's unlikely you'll be able to beat its performance for string comparisons
If this is an xml file that you are downloading, I don't know of any way to speed up your parsing time. However, if you can include it in the apk as a resource (in the res/xml folder), then it will be compiled into Android's binary xml format when you build the apk, and you can access it via XmlResourceParser, which should be significantly faster
我会使用古老的
String.compareTo(String)
。目前可能存在更快的方法,但
compareTo()
是标准方法,因此是唯一能够受益于 Android 未来优化的方法。因此,最终优化的比较可能会比标准方法慢。这与成员字段访问时间非常相似。在 Android 诞生之初,它的速度
比以前
要快得多,但现在情况已不再如此。
I would use the goold old
String.compareTo(String)
.A faster way may exist right now, but
compareTo()
is the standard way, and is therefore the only that will benefit of future optimizations made by Android. So at the end an optimized comparison may become slower than the standard way to do.This is quite similar to the member fields access time. At the beginning of Android it was way faster to do
than
But this is no longer the case.