Android performance 2: Loop speed and the Dalvik VM
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.)
Conclusions:
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.
-
Anthony
-
Anthony
-
http://www.1cheapnookawatchesforsale.co.cc Adelard
-
http://www.1cheapcitizenwatchesforsale.co.cc Adlai
-
http://www.1cheapjustblingwatchesforsale.co.cc Damen
-
leogoldwin2010
-
longtailor
-
Matt
