This Google IO video has some useful info on how to make Android
parsing faster: 
http://code.google.com/events/io/sessions/CodingLifeBatteryLife.html

To summarize, a streaming XML parser is better than DOM, and a binary
format like protobuf is is faster than that.

I hope you are parsing in a different thread than the UI.


Yusuf Saib
Android
·T· · ·Mobile· stick together
The views, opinions and statements in this email are those of the
author solely in their individual capacity, and do not necessarily
represent those of T-Mobile USA, Inc.



On Sep 14, 10:49 am, John <[email protected]> wrote:
> fadden wrote:
>
> >  http://developer.android.com/guide/developing/tools/traceview.html
>
> Thanks for the excellent link.
>
> More testing has brought the parsetime down to about 2 minutes on my
> emulator - I believe the 8 minutes I quoted above was for a parse with
> SAX, but perhaps other things were happening on my machine at the
> time. The two main things I've changed are:
>
> - replaced as many BufferedInputStream.read() with
> BufferedInputStream.read( char[], int, int ), where I easily can.
> - replaced Double.valueOf( Double.valueOf( String.valueOf( buf, 0,
> len ) ).doubleValue() * 1E6 ).intValue() with my own allocationless 24
> line routine:
>
> // char[] to int * 1E6 converter
> // seems to work for me - your mileage may vary!
> public int convCharArrayToInt1E6( byte[] buf, int start, int len )
> throws SchemaException {
>         int rc = 0;
>         int i = 0, j = 0;
>         for( i=start; i<start+len; i++ ) {
>                 if( buf[i] != '-' && buf[i] != '.' )
>                         CHAR_BUF[j++] = (char) buf[i];
>         }
>
>         // determine where 1st digit is as there may be a '-'
>         int firstDig = (buf[start] == '-' ? 1 : 0);
>
>         // USGS KML uses ##.######## format
>         // determine # of digits to make 'millionths of a degree'
>         int dot = (buf[ start + firstDig + 1 ] == '.' ? 7 : (buf[ start +
> firstDig + 2 ] == '.' ? 8 : (buf[ start + firstDig + 3 ] == '.' ? 9 :
> 0) ) );
>         if( dot == 0 ) { throw new SchemaException(); }
>
>         // build int
>         rc = 0;
>         for( i=0; i < dot; i++ ) {
>                 rc = rc * 10 + ( i < j ? (int) CHAR_BUF[i] - (int) '0' : 0 );
>         }
>
>         rc = (buf[start] == '-' ? -rc : rc); // neg check
>         return rc;
>
> }
>
> From the device bogomips numbers I've seen on the net, real devices
> appear to be 2x my emulator. So, if the file only takes a minute to
> parse and I only need to do this once an hour I'm much closer to done.
> Thanks for the help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/android-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to