In embedded/mobile environment battery power drain has to be considered when we are developing Software for it, therefore energy efficient software programming matters in embedded/mobile world.
Problem is,(regarding Assembly/C/C++)
Think we have stable software release when it's run on arbitrary platform X it consumesY amount of power(in Watts), now we are going to carry out some code change and we want to measure how it's gonna effect on energy consumption and its efficiency at build time.
INT16U x = OXFFFF;
/... some code in stable release .../
for(;x<4096;++x)
{
/... some code in stable release .../
INT64U foo = x >> 256 ? x : 4096 ; // point 1 sample code change;
if(~foo & foo) foo %= 64 ; // point 1 sample code change;
/... some code in stable release .../
}
Simply if we want to measure how this code change @point1
effects on energy efficiency(relative to the stable release statistics) rather than profiling space and time (performance plus memory), If we want to build a simple energy/power analyzing and profiling tool in C/ C++,
point1
, how can we determine power consumption for each instruction for arbitrary CPU or GPU on the respective platform?TL;DR You can't do it with software, only with a physical meter.
To refine what "@Some programmer dude" already hinted at:
One problem is, that the actual implementation of a certain operation on hardware is unknown. You might get lists with cycles/opcode but you do not know what those cycles do. The can go a long route around, some need more parts to pass some less and so on, hence it is unknown how much power the individual cycle needs.
Another problem are the nearly indeterministic paths in complex code with a large-domain (e.g. 16-bit ADCs) and multiple inputs (e.g.: reading several sensors at once.), especially if you work with floating-point arithmetic.
It is possible to get relative differences in power consumption but only coarse ones. Coarse like in "100 loops of the same code need more power than 10" coarse. Or: if it runs faster it most likely needs less power.
No, you have to swallow the bitter pill and go to the next Rhode&Schwarz (not affiliated, just saw an ad in the sidebar at the moment of writing this) shop and get a power-supply, a meter (two, actually), a frequency generator and the necessary connecting material. Will set you short in the mid to upper five digit range (US $). Once you have it you need to measure the power consumption of several MCUs/CPUs (ca. 30+ to be able to assume uniform distribution) of every single batch of the processor you got.
That is a lot of work and investment if you don't have the tools already. Measuring is also a form of art in itself, you need to know what you are doing, a lot of things can get wrong.
It might be a good idea to spend that money if you want a million dollar contract with the military and need to guarantee your stuff to be able to run five years on a single battery (and the first thing said military does is slapping a sticker on it that says "Change battery every 6 month!") otherwise: don't even start, not worth the headaches.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With