Green programming: C and Rust energy-efficient, Python and Perl at the bottom

1662783961 green programming c and rust energy efficient python and perl at.jpg
1662783961 green programming c and rust energy efficient python and perl at.jpg

A study has examined the energy consumption of programming languages ​​and offers tips for energy-conscious programming. C and Rust perform best.


The electronic processes in our post-analogue world and the operation of its infrastructure cost resources. But not only the operation of servers for the cloud, machine learning or streaming films are associated with power consumption, as is often the first thing that springs to mind.


Writing this message, calling it up in the browser and displaying it on a screen also consume electricity, which adds up. It may be less obvious that programming itself and the choice of programming language used is a factor that may have a greater impact on the life cycle assessment of applications than is generally known.

A paper by Portuguese scientists examined the energy efficiency of programming languages ​​a long time ago and found that the energy consumption varies greatly. In the current energy crisis it is worth taking a fresh look at the results. According to the research team, speed (fast or slow) and memory requirements are major factors in the energy consumption of programming languages. The research team led by Rui Pereira from the Universities of Minho, Coimbra and Lisbon examined a total of 27 programming languages ​​with different paradigms in detail with regard to their performance and energy consumption and compared them for benchmarks.

The team measured code execution time (Time) and peak memory usage (Memory). She related both to energy consumption and examined how time and consumption are related. As a result, faster languages ​​are not automatically more energy-efficient. The results should enable developers to program more energy-consciously. Since development teams often have limited resources, Pereira and his colleagues ranked their results according to different combinations of the characteristics they examined.

In terms of methodology, Pereira and his team use the “Computer Language Benchmark Game” (CLBG) software repository. It provides a way to quantify the energy footprint of software. At the time of writing, CLBG summarized thirteen benchmark problems, ten of which were relevant to the research question. The solutions to each of these problems must follow a specific algorithm and adhere to specific implementation guidelines. There are two tables in the paper that list the computational problems in full and list the compared programming languages ​​sorted by their paradigms (functional, imperative, object-oriented, and scripting languages). The benchmark game can take into account up to 28 programming languages ​​per comparison. The study considered 27 languages ​​since small talk was excluded.



The results can be summarized in a normalized table that breaks down the energy, time and memory requirements in a comparable manner. The best performers were C and Rust (rated on the CLBG comparison scale with energy scores of 1.00 and 1.03, respectively), closely followed by C++ (1.34). Then followed Ada and Java, Pascal, Chapel and Lisp (about twice the consumption of C and Rust, between 1.70 and 2.27). Languages ​​like Ocaml, Fortran and Swift also had presentable values ​​(2.5 to 3 times the consumption compared to C and Rust). Haskell, C#, Go and Dart performed passably (between three and four times the consumption), F# and JavaScript (four times the energy consumption of C and Rust) and Racket (with a value of 7.91 about eight times the consumption) were a little more energy-hungry.



After that, the table makes a big jump, and for the other languages ​​examined, the energy requirement increases twenty to eighty times compared to the top of the table. At the bottom of the comparison is Perl (79.58), but Python does not perform much better either, with energy consumption that is 75 times higher than Rust (75.88 according to the table). This is remarkable as Python is among the most popular programming languages ​​and is considered fundamental in data science and machine learning because of its extensive and well-established ecosystem.

In the environment of developer specialist authors, it has already been heard that some machine learners are deliberately writing their ML engines in C or Rust, Python apparently does not have the best reputation in terms of performance. A specialist author drew the editors’ attention to the study via Twitter. In descending order, the table closes with Ruby (69.91), Jruby (46.54), Lua (45.98), common in game programming, Erlang (42.23). PHP, Hack, and TypeScript performed only moderately better (with respective scores of 29.30, 24.02, and 21.50 in the comparison chart).

While machine learning and data science are searching for efficient techniques on the hardware and software side, for example more powerful hardware, more energy-efficient algorithms or sparsity approaches for artificial neural networks, it seems to be particularly worthwhile going into depth here to drill. In view of rising energy prices and possible electricity and gas shortages, the findings of the Portuguese research team are of renewed relevance and could influence the decisions of software developers when the question of which language to choose for the next project is in the air.

Apparently the focus of a project is decisive here instead of general rankings of the entire energy balance. Pereira and team created a Pareto-optimized set of different target parameters that teams could use as a cheat sheet:


If you want to delve deeper into the topic, you can read the research paper at Greenlab. For further reading, we recommend the specialist article by Oliver Heinrich “Climate Aware Programming”, published by voonze developer.

Recent investigations by the research group correspond to the present study (“Ranking Programming Languages ​​by Energy Efficiency”). It would certainly be interesting to take a look at the low-code area as well.


Previous articleFacebook affirms pseudonymised identifiers as protection against scrapers
Next articleDynamic Island: First only for Apple, other apps will have to wait
Brian Adam
Professional Blogger, V logger, traveler and explorer of new horizons.