开发者

Fast string comparison using Dalvik VM?

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?


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


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

final AnyClass local = mMyMember;
local.something();

than

mMyMember.something();

But this is no longer the case.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜