In my first blog post Towards Leaner Software, I wrote about the importance of runtime performance in terms of CPU and memory efficiency. After reading the paper “Energy Efficiency across Programming Languages”, I realized I hadn’t given much thought to energy consumption of programs and had assumed (incorrectly) that faster execution corresponded to better energy efficiency. If engineers choose languages, data structures and design patterns that result in the least energy consumption, it will help software run better on mobile devices and cloud data centers, two areas where computing is growing the fastest.

In the paper, the authors used the Computer Language Benchmarks Game (CLBG) to analyze several programming languages using micro-benchmarks from CLBG. They measured performance of programming languages by measuring

  • execution time
  • memory used
  • energy consumed

and they categorized languages into three categories based on the execution type:

  • compiled
  • virtual machine
  • interpreted

and also based on the primary programming paradigm supported by the languages:

  • functional
  • imperative
  • object-oriented
  • scripting

Here are some important findings:

  1. It’s not necessary that the fastest programming language is the most energy efficient
  2. Compiled languages that support imperative programming are the fastest, use the least memory and are the most energy-efficient
  3. The fastest and most energy-efficient languages are C, Rust and C++, in that order
  4. The top 5 languages that use the least memory are Pascal, Go, C, Fortran and C++

Unsurprisingly, all of the system programming languages I had mentioned in my previous post Systems Programming were found to be the best based on time, memory and energy used. I wish they had benchmarked D and Nim as well, but I suspect they would have landed in the top 10 as well. I think when I write code moving forward, I’ll be more energy-aware.