How Environmental Friendly is Programming Languages

One thing that I have wondered about for a while is which programming language is the most environmentally friendly for the climate. Over my career, I have used many different programming languages, starting with Assembly as we build Operating Systems and working very closely with the hardware. Over the years, I got away from working closely with hardware, and now I primarily program in Python, PHP, Javascript and TypeScript.

I was not sure how I would get the information I was looking for to understand a programming language’s impact on the environment. Doing research, I found that a team of Portuguese university researchers attempted to quantify the energy efficiency of programming languages in a paper entitled Energy Efficiency across Programming Languages published in 2017. They looked at the runtime, memory usage, and energy consumption of twenty-seven well-known programming languages.

C is the most efficient programming language, while Python and Perl are the least environmental friendly programming languages.

The researcher’s focus was to understand the energy efficiency across various programming languages. This might seem like a simple task, but it is not as easy to define. They had to properly compare the energy efficiency between programming languages and various comparable implementations with a good representation of different problems/solutions.

The researchers obtained a comparable, representative and extensive set of programs written in many of the most popular and widely used programming languages by using the Computer Language Benchmarks Game (CLBG) method.

The CLBG initiative includes a framework for running, testing and comparing implemented solutions for a set of well-known, diverse programming problems.

From the 28 languages considered in the CLBG, the researchers excluded Smalltalk since the compiler for that language is proprietary. Also, for comparability, they discarded benchmark problems whose language coverage is below the threshold of 80%.

The outcome of the study shows that compiled languages tend to be the fastest and most energy-efficient ones. On average, compiled languages consumed 120J to execute the test solutions, while for the virtual machine and interpreted languages, this value was 576J and 2365J, respectively. This tendency can also be observed in execution time since compiled languages took

To understand this in more detail, we can take the binary-trees results to illustrate the point, starting with compiled code.

The graph concludes that “compiled languages tend to be the fastest and most energy-efficient ones.” C and C++ languages are the most efficient and fastest languages. Go is the worst language from the compiled languages category.

Next, we look at the binary trees in a VM that show us that Java or Erlang is the most efficient but far after compiled.

The inefficient languages go to interpreted languages like Perl, Lua, or Python, and that’s by some margin.

The study tests were performed on a machine based on an Intel Core i5-4460 Haswell CPU @ 3.20GHz with 16GB of RAM, and running Ubuntu Server 16.10 operating system with Linux 4.8.0-22.

The researcher ranked each language with different combinations of objectives mixing time, memory, and energy parameters, and C is coming out at the top. This study shows the efficiency of programming languages. If you are concerned about climate change, make your choice of programming language for your next project.

To sum it up

This was an eye-opening exercise for me. I have gone from using the more efficient languages like C and Assembly to some of the more environmentally inefficient programming languages like Python, PHP. It looks like I have been cutting corners going for programming languages that are easier to use. It also shows that the more efficient languages do not do that are used for the internet,

It would be interesting to do a study on what is the most efficient programming languages to build digital solutions for the web, mobile or desktop that is where we are to today. Making the right programming language choices when building new digital solutions for a sustainable further is important to us all.



6 responses to “How Environmental Friendly is Programming Languages”

  1. Don Avatar

    Other costs involved are the development time, and time to identify and fix bugs. These will have human input, so the cost goes up to cover cost of lighting, heating/cooling, general human consumption, while working on that and not the next piece of code. However these costs will be reduced if spread over larger user bases.

    But the point is that languages easier to use will have a lower cost. I suspect it is possible that the more expensive languages are easier to use, and also often used by smaller user bases.

    1. Laurent Avatar

      This would have been good instead of just looking at the problem only from the point of view of the Environment – which is already a good starting point, it would have been interesting to look at it from the broader perspective of ESG. And then indeed, the Social (peoples) aspect might eventually change the score, even if it could be tainted with some bias. All these languages have different ages, some more widely used than others, and this is for different reasons that bring other sets of biases.

  2. Schönherz Lakatos Műhely Avatar
    Schönherz Lakatos Műhely

    Which Python version did you use? 2 or 3?

    1. torbjorn Avatar

      It is nor clear from the Reserach Paper which version – here is the libk to the research paper

  3. […] How Environmental Friendly is Programming Languages […]

  4. Rui Craveiro Avatar
    Rui Craveiro

    Dart is mischaracterised here, because it is not necessarily an interpreted language. Dart may be compiled to JavaScript and run on a browser, which is an interpreted use of it. However, Dart also compiles to native code, so it runs natively on Android, iOS, Linux, Windows and MacOS. It would have made sense to present Dart(JS) and Dart(AOT) as if they were 2 different languages, because while there is absolutely no difference in syntax and semantics, the runtime efficiency is certainty very different depending on how which output of the language we use.

Leave a Reply

Your email address will not be published. Required fields are marked *