Search code examples
javaandroiddatabasebattery

Android: Do database operations consume power?


An Android app (Java) needs to update the same database record periodically. It can be done every second or every minute. Regarding only battery life, Does it make any significant difference (like shortening the battery life to half) doing it every second v/s every minute?

As only CPU and memory are involved, I think it makes no difference, but I'm not sure. CPU and memory are still used by the running app & other system process, anyway.

Updating every second makes a simple app; caching and updating every minute (or waiting for certain condition) make code a little more complicated and error prone.


Solution

  • I agree with CommonsWare's answer - if you don't need to be doing something every second and can do it less frequently, then the best practice is to reduce the frequency as much as possible, as doing it more frequently will consume more energy.

    However, to address the "significant" part of your question, especially in relation to other device operations, consider this following quote based on tests on the HTC Dream (G1) and Nexus One devices, from:

    • Aaron Carroll and Gernot Heiser, "An analysis of power consumption in a smartphone," presented at the Proceedings of the 2010 USENIX conference on USENIX annual technical conference, Boston, MA, 2010. http://www.nicta.com.au/pub?doc=3587

    "The RAM, audio and flash subsystems consistently showed the lowest power consumption. While our micro-benchmarks showed that the peak power of the SD card could be substantial ( 50 mW), in practice the utilisation is low enough such that on average, negligible power is consumed. Even video playback, one of the more data-intensive uses of mobile devices, showed SD power well under 1 % of total power. RAM has similar characteristics; micro-benchmarks showed that RAM power can exceed CPU power in certain workloads, but in practical situations, CPU power overshadows RAM by a factor of two or more. Audio displayed a largely static power consumption in the range of 28–34 mW. Overall, RAM, audio and SD have little effect on the power consumption of the device, and therefore offer little potential for energy optimisation."

    Keeping the CPU busy when it otherwise wouldn't be is likely the largest energy impact of continuously writing to the database every second, vs. writing every minute. Relatively, assuming normal usage, flash memory use in isolation consumes relatively little energy.

    If you're interested in additional references and discussion, see: https://stackoverflow.com/a/13004377/937715