How to Go Green with Your Code
Computer manufacturers and the ENERGY STAR program have had great success improving the efficiency of computer hardware. But did you know that the software the computer uses can also have a tremendous impact on the amount of energy consumed? Software is critical to making the technology we use function properly and gives us access to many valuable features. Like the computer hardware, software can be designed to be more efficient.
ENERGY STAR recommends these best practices to help you write better, more efficient software code.
- Make your code lean - Avoid redundant and sloppy code, such as improper resource release, flawed loop structures, or overly complex functions.
- Avoid static periodic function calls – This forces a device to remain awake when it would otherwise enter a low power energy saving mode, which is the default for most ENERGY STAR certified consumer electronic and IT products.
- Provide user-selectable dark mode GUI options (when applicable) - This implements true black backgrounds (0,0,0 in RGB or #000000 in hex) to decrease the energy draw of OLED and other developing emissive display technologies.
- Consider your software language - Write your software in compiled languages rather than interpreted languages. Many interpreted languages (Java being an exception) can use over 4 times the amount of energy to complete the same task, in part because of the increased use of total system memory[1].
- C, C++ and Java are common languages that are particularly efficient, while Python, Ruby and Javascript are popular languages that are typically very inefficient.
- Blockchain Solutions – Implement proof of stake rather than proof of work.
Existing tools can help you understand and improve the efficiency of your software code. An example is Texas State University’s GreenCode project which allows users to input code, run it, and see the runtime and energy consumption of that code. This tool supports 20 different, common programming languages.
Using more efficient software languages and taking time to write energy efficient software allows for a better user experience, such as extended battery life and more responsive and stable software, and less energy consumption-- a win-win for the environment and the customer engaging with your software.
[1] https://haslab.github.io/SAFER/scp21.pdf
Author