It starts with pixels

Android performance 2: Loop speed and the Dalvik VM

with 8 comments

Let’s run a simple benchmark on the G1.

I had noticed that Android was running on some Java virtual machine called Dalvik, but hadn’t given it much attention otherwise.  It turns out to be pretty important, after all.  As far as I can tell, Google decided it would be a good idea to favor a small memory footprint over speed.  Here’s the benchmark I just performed:

long start = android.os.SystemClock.uptimeMillis();
int[] image = new int[8*320*400];
for(int i = 0; i < (8*320*480); i++) {
   image[i] = i;
long end = android.os.SystemClock.uptimeMillis();
long elapsed = end - start;

So, how long did it take?

  • G1 (R29 firmware):  922 milliseconds.
  • G1 (R29 firmware).  Loop only.  520 milliseconds.

And, for comparison:

  • Fujitsu T4220 (2.4 GHz Intel T7700).  C#. 14 milliseconds.
  • Fujitsu T4220 (2.4 GHz Intel T7700).  Java. 16 milliseconds.

Note: I ran everything in “Run” mode (not Debug mode).  (Debug mode causes the G1 to run about 4X slower in this benchmark.)


Dalvik puts a big wall between you and the (already pretty slow) CPU.

It is claimed that Dalvik is designed for slow machines with low memory, powered by a battery.  However, I don’t understand how the Dalvik interpret-only VM actually achieves this, other than through programmer castration.  What does that mean?  Well, you can’t really do much on Android that isn’t built into the runtime, or your application will crawl, and you’ll be forced to strip those features out and rely on the optimized ones that are built into the libraries.  The memory footprint for Dalvik is lower, because there’s no JIT compiled chunks of code sitting in RAM.  But isn’t RAM cheap, fast, and low-power these days?

Next time (Android performance 3):

  • A duel with the iPhone.  I’d like to run this same trivial benchmark on an iPhone in Objective C and see what happens.

Written by jeff

October 31st, 2008 at 10:14 pm

Posted in android,technology

Tagged with , ,

  • Anthony

    FYI…I just ran this on my HTC Hero:

    for(int i = 0; i < (8*320*480); i++) {
    int[] image = new int[8*320*400];
    for(int j = 0; j < (8*320*480); j++) {
    image[j] = j;

    Total time: 10.5 seconds

    That would still be 5x the old iPhone. I wonder how this compares to the 3G or 3GS?


  • Anthony

    Sorry…ignore that last post. Ran the wrong routine and posted the wrong time.

    Here's the routine that I now ran:

    for(int i = 0; i < 50; i++) {
    int[] image = new int[8*320*480];
    for(int j = 0; j < (8*320*480); j++) {
    image[j] = j;

    This took 34 seconds on my HTC Hero (v1.5 Cupcake).

  • Adelard

    Fantastic Evening, I usually do not usually submit feedback on web, as I favor to learn only. Even so I uncover the article that you might have written previously has very insightful details, and that i learn it incredibly informational. I was looking on Aol 4 facts on self improvement and observed your priceless post. Could you submit some thing the exact same insightful on how you can self improve quick? Cheers.

  • Adlai

    I’m starting my personal weblog to share my photography experiences. Do you discover it challenging or easy to put up constantly?

  • Damen

    I?ve not too long ago started a website, the facts you produce on this web page has aided me tremendously. Many thanks for all of your time & operate.

  • leogoldwin2010

    I think people should just trust the government. Too bad that most people continue to be suspicious of government. I believe whatever the government do, it is for the sake of the citizen pajama jeans

  • longtailor

    there's an interesting Android performance benchmarking app named Quadrant and is probably the most popular Android performance benchmark app available today. it eases some steps considerably:-) I've used it with my samsung gsm and found it’s been making the rounds as people jump on board to test their Android phones against the big guns!

  • Matt

    Well the Dalvik VM was always going to be succesful, just like nitric pure