With the price of electricity through the roof, trying to be more efficient is a shared goal in all kinds of areas. We are looking for plans B of all kinds to minimize dependencies and extra consumption. And an area in which it is also possible to set this objective is software development. How to program more efficiently?
What programming language spends less electricity? A study carried out by Portuguese researchers already tried to answer this question in 2017. In their analysis —the code used is available on GitHub— they considered both the use of memory and the energy consumed in the execution of a special set of programs.
Measuring consumption. This set of programs is called Computer Language Benchmarks Game and it is a Free Software project that allows you to compare how certain algorithms are implemented in different programming languages. In this process, the execution time, memory consumption or CPU usage are analyzed.
C, Rust and C++ win separately. When studying power consumption, execution time and memory consumed, the normalized data shows C, Rust and C++ as winners. Among the worst behaved were Python, Perl, Ruby, Lua or PHP. There are also curiosities: very old languages such as Pascal or Fortran do not consume much, but their low memory usage is striking, probably because they were designed when that resource was especially limited. In general compiled languages seem to be more efficient than interpreted ones.
let’s make couples. Although that was the general classification, the researchers also wanted to give options to those seeking to solve combined efficiency problems. Thus, they indicated the best languages to save execution time and memory (C, Pascal and Go win), energy and time (C, Rust and C++), energy and memory (C and Pascal) or the three objectives, energy, time and memory (C, Pascal and Go stand out).
An imperfect study. The study has already sparked debate on social media. like twitter, and in comments on Hacker News several developers indicated that the code was not ideal for comparison. Thus, a user explained that this code “does not reflect how languages like Python behave in practice”, but in reality the question is not that.
Efficiency is not the priority. As another user explained, if you want to be really efficient, the ideal would be to program in assembler. Although it may be interesting to know which language is more efficient, it is even more important to be clear that certain programming languages are perfect for some things, while others are for others. In fact, in this area, what is clear is that the most popular programming languages are not the most popular —Rust is the most fashionable, for example— nor are they the ones that make the most money.
Image | james harrison
George is Digismak’s reported cum editor with 13 years of experience in Journalism