On Sep 1, 7:18 pm, WoodManEXP <[email protected]> wrote:
> In any event the Android seems really slow becasue a block like
>
> for(int i=0; i<1000000;i++) {
>   c[i] = b[i]
>
> }
>
> takes like 20-25 seconds to execute (On Intel Pentium, eq #, such a
> thing executes in a flash).

On a G1, I can do twice that many in well under a second:

  Filling...
  Copying...
  Done in 484.527591 ms.

Complete code is:

public class Foo {
    public static final int SIZE = 2 * 1000 * 1000;

    public static void main(String[] args) {
        byte[] bigByte = new byte[SIZE];
        char[] bigChar = new char[SIZE];
        long startWhen, endWhen;
        int i;

        System.out.println("Filling...");
        for (i = 0; i < SIZE; i++)
            bigByte[i] = (byte) i;

        System.out.println("Copying...");
        startWhen = System.nanoTime();

        for (i = 0; i < SIZE; i++) {
            bigChar[i] = (char) (bigByte[i] & 0xff);
        }

        endWhen = System.nanoTime();
        System.out.println("Done in " + (endWhen - startWhen) /
1000000.0
            + " ms.");
    }
}

(Instructions for running stand-alone tests on the G1 can be found in
dalvik/docs/hello-world.html)
  
http://android.git.kernel.org/?p=platform/dalvik.git;a=blob_plain;f=docs/hello-world.html;hb=HEAD

Changing it to merge pairs of bytes into a short:
        char[] bigChar = new char[SIZE/2];
  ...
        for (i = 0; i < SIZE/2; i++) {
            bigChar[i] = (char)
                (bigByte[i << 1] & 0xff | bigByte[(i << 1)+1] << 8);
        }

increased the time to 780.5 ms.  Nowhere near the 20+ seconds you're
seeing.

Is there a chance that your code is running so slowly because
something else in your app or in the system is thrashing?

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to