An open source coding group I participate in similarly wrote our own faster float parsing: http://code.google.com/p/skylight1/source/browse/trunk/SkylightOpenGL/src/skylight1/opengl/files/QuickParseUtil.java#23
Took parsing 1000 strings from 465ms to 12ms, although it just handles what we need it to specifically, not everything. Interesting seeing the other implementations linked from and in this thread! Although in our particular case, just parsing the OBJ files into exactly the bytes they end up as in the graphics buffer and saving that to a file in res/ raw before building the app would be the ultimate solution... -- Lance Nanek - Software Developer http://neatocode.com | http://twitter.com/LanceNanek | http://www.youtube.com/user/lnanek On Apr 14, 8:05 pm, ip332 <iprile...@gmail.com> wrote: > public class String2Float { > final int max_exp = 38; > final int max_str_len = 20; > float [] values; > char [] buffer; > > public String2Float() { > buffer = new char [max_str_len + 1]; > values = new float [max_exp + 1]; > values[ 0 ] = 1; > for( int i = 1; i < max_exp; i++ ) { > values[ i ] = values[ i - 1 ] * 10; > } > } > > public float Value(String str) { > int len = str.length(); > if( len > max_str_len ) > len = max_str_len; // ToDo: add proper error handling > // extract all characters into the local buffer > str.getChars(0, len - 1, buffer, 0); > // find decimal point > int point_idx = len; > for( int i = 0; i < len; i++ ) { > if( buffer[i] == '.' ) { > point_idx = i; > break; > } > } > // process all digits before the decimal point > float res = 0; > for( int i = 0; i < point_idx ; i++ ) { > int digit = buffer[i] - '0'; > float value = digit * values[point_idx - i - 1]; > res += value; > } > // process all digits after the decimal point > for( int i = point_idx + 1; i < len; i++ ) { > int digit = buffer[i] - '0'; > float value = digit / values[i - point_idx]; > res += value; > } > return res; > } > > } > > On Apr 14, 5:02 pm, Mark Murphy <mmur...@commonsware.com> wrote: > > > > > > > > > On Thu, Apr 14, 2011 at 7:47 PM, Paul <pmmen...@gmail.com> wrote: > > > OK, have stripped the FloatingPointParser bare, but can't run it as > > > the native method, parseFltImpl() is throwing an > > > UnsatisfiedLinkError... > > > > Maybe a silly question, but any ideas what to do from here? > > > Start from scratch, as Gaz Davidson did here: > > >http://bitplane.net/2010/08/java-float-fast-parser/ > > > Or, as the last comment on that blog post indicates, grab the latest > > code from Harmony and try it. > > > Or, roll your own String->Float using JNI and the NDK. > > > -- > > Mark Murphy (a Commons > > Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy > > > Android Training in NYC:http://marakana.com/training/android/ -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en