Is there anything that can be done for a single general purpose application to affect the power consumption of the device it is running on?
I am not familiar with how optimizations to individual applications may affect power consumption in a general way, can someone explain if different approaches to writing applications affect power consumption of the device they are running on?
That is, can a single program, that does the exact same thing functionally, written in different ways drastically affect the power consumption of a device in general, not about how different un-related programs might affect the power consumption of a device.
11
Power consumption concerns are often to detriment of performance, so the two need to be balanced. Apply cost of capital accounting to consider more efficient hardware, and it becomes a very complex tradeoff. (simply do you spend 100 hours to save a milliwatt/hour, or $10 for a more efficent PSU in the conputers running the software). The only time it makes commercial sense to worry about power consumption (caused by software) is a server farm the size Google runs, battery powered devices, and if marketing want a tick on the Tree Hugging Greenie box.
Its too complex to trivialise it by saying “Make you algorithms more effiecent” – thats just the first step. The performance/power curve and particular the “perceived performance”/power curve are non linear. It depends if you have control and to what level through the OS in use.
Beyond that, the question will have different answers to each specific situation. For instance I once worked on a battery powered system (target 18 months on a 9V cell) that was more power efficent running at max clock speed for short duration than sleeping, yet another micro running similar software was better to tick over on a slow clock for a minute or so then sleep.
8
The best thing that you can do is optimize your algorithms and the business logic of your application.
You can also adopt a particular compiling process, many coders just forget about inline functions and optimization in a compilation phase, most of the time this gives you a small edge in terms of performance and, consequently, in terms of power consumption optimization.
7
The right answer is ….
"We should forget about small efficiencies,
say about 97% of the time: premature
optimization is the root of all evil"
Donald Knuth
Focus on providing value to your clients. Create solution that is clean, easy to understand and easy to maintain.
Then if you need more “power” you can profile your application. With profiling you will pin point bottlenecks that when changed, will provide biggest benefit and boost in “efficency”.
2
While it is true that in terms of the CPU there isn’t much to be done, there are often features of the device that consume power when used. On a PC, mostly no one cares, but it is definitely true that a disk read will (assuming non-SSD drives) cause the hard drive to spin and the head to move, which will consume some bit of power. On a PC this is trivial, but on a mobile device, this can be a very real issue.
On a phone, the most obviously example of this is communications. Sending a wireless signal takes energy. On a PC, connected to a 500 WATT power supply, it is inconsequential. On a phone, it is not. An application that constantly polls a server for large amounts of data will use dramatically more power than one that uses no network at all.
This is a very real issue, just google for “Android application drained my battery”. Here is one of many pages telling developers how to minimize power consumption.
In general, you want to optimize for performance in general (i.e. make the CPU as much as possible) and also for network usage. Communicate as little as possible with as small messages as possible.
As others have said, this is a task for after most of your code is complete, when you’ve identified an issue and profiled power use.