Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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.

share|improve this question
8  
Make it perform more efficiently. –  Christopher Berman Jul 13 '12 at 18:44
    
I'm not saying your question is outright off-topic, but I think a book will be more suitable than an answer in a Q&A site. You should provide at least some context, like is this embedded systems, mobile development or something else entirely. Any answer should depend heavily on that. –  K.Steff Jul 13 '12 at 20:44
2  
Are you talking about battery-powered embedded systems? In general, the key to minimizing power consumption is to identify times when the system really won't have to be doing much, and minimize the amount of time that any part of the system will be active when there isn't really anything for it to do. In most cases, there will be a pretty clear limit as to how much effort is worthwhile; if a device will use 1mAH/day on necessary functions, a simple routine which wastes 10uAH/day may be preferable to a complex one which only wastes 1uAH/day (since the latter would only save 1% on energy). –  supercat Jul 13 '12 at 21:18
1  
I was thinking in something general, not with a context in particular. It was a 'just for curiosity' question. But for example, is there any rule for powersaving on mobile devices? or embeded systems? or on web applications development ? May be delaying disk accesses and networking or things like that. –  Juan Manuel Jul 13 '12 at 21:22
1  
I suspect you are missing the point. If you change an application to use the radio half as much, you will see power consumption when that application run go down. The radio on a phone is not drawing power at a constant rate. It's power drain depends directly on what it is being asked to do by the software. –  Steven Burnap Jul 14 '12 at 19:58

4 Answers 4

up vote 7 down vote accepted

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.

share|improve this answer
    
this is actually the correct answer, hardware plays a much more affective role in power consumption than software. The example of a more efficient PSU makes ALL of the device, and overshadows micro-optimizations of single applications making them insignificant contributions. –  Jarrod Roberson Jul 14 '12 at 4:22
    
Yes, but a program doesn't use every bit of hardware on the device equally. For example, a program that never uses the hard drive on a PC will use significantly less power than one that is constantly reading from and writing to the hard drive. –  Steven Burnap Jul 14 '12 at 17:19
    
@StevenBurnap that is irrelevant depending on the HD, some HD spin and pull juice all the time. The most significant power optimizations will always come from hardware ( and the microcode in them ). The same software with a Green HD will use less power, so hardware still makes more of a difference. –  Jarrod Roberson Jul 14 '12 at 19:00
2  
That is not true. Attach a Kill-a-watt to your system, and run two applications, first one that just adds numbers in an infinite loop, and another that scans a 5 GB file repeatedly. You will see a difference. Power consumption definitely will vary on a computer, sometimes dramatically, depending on what it is being asked to do. –  Steven Burnap Jul 14 '12 at 19:54
    
Here's an example that shows a PC's power consumption changing based purely on what software is running: codinghorror.com/blog/2005/08/… –  Steven Burnap Jul 14 '12 at 20:00

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.

share|improve this answer

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".

share|improve this answer
4  
I'd say this doesn't answer the question, since you're saying "Power consumption is not your problem; focus on value for clients". And it sounds a lot like some management mantra. The OP might have serious justification for requiring lower power consumption. –  K.Steff Jul 13 '12 at 19:56
    
Well i misunderstood "power consumption". Still i think he should set up a level of power consumption that when reached, optimization should be performed by analysing parts of the system that are eating too much power. This could be performed by series of stress tests. –  Michal Franc Jul 13 '12 at 20:01

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.

share|improve this answer
    
This is the right answer. Optimizing is the only way. –  superM Jul 13 '12 at 18:51
1  
How is this the right answer? There are far more power sinks in a system than the CPU. –  James Jul 13 '12 at 22:09
1  
@James your software only uses the CPU? nothing else? –  user827992 Jul 13 '12 at 22:13
3  
@user827992: No, that's the point. Things like the radio (GSM/3G/Wifi) and the screen consume far more power than a CPU. Optimising your algorithms won't help you here. I'd go so far as to say that in system where power consumption is a concern, optimising your code is a premature optimisation. –  James Jul 13 '12 at 22:19
1  
@user827992: Yes but these savings are miniscule compared to other sources of battery consumption. You can optimise to -OInfinity all you like, but if for example, your code polls some flag somewhere you're dead. –  James Jul 13 '12 at 22:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.