First, profile and find out which is the slow part (reading, tokenizing, string-to-float conversion).

Second, conversion of string to float is ridiculously slow in some Java library versions (Android uses Apache Java libraries). This came up in the context of SVG parsing, IIRC, a few months ago, search this group's archives.

-- Kostya

04.10.2011 20:42, bob пишет:
Does anyone know why this code is ridiculously slow and/or how to make
it faster?


        float[] getVertices(String filename) {

                try {
                        AssetManager am = this.getResources().getAssets();
                        InputStream is = am.open(filename);
                        BufferedInputStream bis = new BufferedInputStream(is);
                        Scanner s = new Scanner(bis);
                        long numfloats = s.nextLong();
                        float[] f = new float[(int) numfloats];
                        for (int ctr = 0; ctr<  f.length; ctr++) {
                                f[ctr] = s.nextFloat();
                        }
                        return f;

                } catch (IOException e) {
                        e.printStackTrace();
                        return null;
                }

        }


--
Kostya Vasilyev

--
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

Reply via email to