Is it possible to choose a programming language based on energy, time, and memory usage?

Java is one of the most energy-efficient languages, Python among least energy efficient

Jane Elizabeth
© Shutterstock / amasterphotographer

Energy efficiency isn’t just a hardware problem. Your programming language choices can have serious effects on the efficiency of your energy consumption. We dive deep into what makes a programming language energy efficient.

For years, we’ve conflated performance with processing time. “How well does it do?” meant “how fast is it?” But these days, things have changed. Developers, engineers, and even consumers will do a lot to avoid a heavy drain on the CPU in order to preserve their batteries. Energy efficiency started on the hardware side, but now it’s trickled down into software development.

There are a lot of questions that arise when you try to measure the efficiency of a programming language. For one, what sort of metric are you using? Is a faster program language a more energy efficient one? Is a faster programming language a greener one?

However, comparing languages is difficult. The performance of a language can be easily improved just by the quality of its compiler or virtual machine. Improved source code is as crucial as optimized libraries.

A team of Portuguese researchers studied 27 of the most popular programming languages to see if there was any relationship between speed and efficiency.

SEE MORE: Java is likely to outlive Go: How can we judge which programming languages will survive?

Using the Computer Benchmarks Game, the team of researchers tested these languages by compiling/executing such programs using the state-of-the-art compilers, virtual machines, interpreters, and libraries. They then analyzed the performance of the different implementation considering three variables: execution time, memory consumption and energy consumption.

energy efficient

What Pereira et. al. found wasn’t entirely surprising: speed does not always equate energy efficiency. Compiled languages like C, C++, Rust, and Ada ranked as some of the most energy efficient languages out there.

However, Java is one of the fastest and most energy-efficient object-oriented language. Interpreted languages like Perl, Python, and Ruby were among the least energy efficient. As the researchers discovered, the CPU-based energy consumption always represents the majority of the energy consumed.

On average, if sorted by their programming paradigm, the imperative languages needed the least amount of memory, followed by the object-oriented, the functional, and finally the scripting languages.

SEE MORE: Trending on the charts: Swift hits Top 10 for popular programming languages

So, is it possible to choose a programming language based on energy, time, and memory usage? Well, yes. C is the clear winner across all the fields. But if you’re not interested in coding in C, there are some interesting options.

energy efficient

Go and Pascal do rather poorly in the straight efficiency test, but they do better if you’re considering languages based on time and memory or energy and memory.  For those interested in improved energy and memory, Rust and FORTRAN are also decent options.

Test how efficient your code really is

The researchers have an awesome thing up over at GitHub where they’ll evaluate your code to see how energy efficient it is. It’s only three simple steps.

  1. Create a folder with the name of you benchmark, such as test-benchmark, inside the language you implemented it.
  2. Follow the instructions presented in the Operations section, and fill the Makefile.
  3. Use the compile_all.pyscript to compile, run, and/or measure what you want! Or run it yourself using the make command.

What do you think? Will this change your programming language choices? Let us know in the comments below!


Jane Elizabeth
Jane Elizabeth is an assistant editor for

Inline Feedbacks
View all comments
3 years ago

I think that it is bogus to compare programming languages themselves on the basis of speed. We should compare their implementation’ speeds instead. I wrote a whole blog post about it: Let me know what you think of it!

Ramses Alexander Coraspe Valdez
Ramses Alexander Coraspe Valdez
Reply to  Giedrius
2 years ago

thanks for this information.

Paul Miller
Paul Miller
2 years ago

@Giedrius no, but programming instructions have a time and space consumption and therefore an energy consumption.

Languages without a memory primitive (eg pointers) or a way to express value types mostly treat everything as a memory address (which is really bad for cpu caching and therefore energy consumption).

1 year ago

Dynamic power is directly related to the number of clocks (ticks) instructions take to finish. Low-level languages like C/Rust/C++ require fewer number of instructions to be executed in a CPU compared to high level languages (Python/Ruby/R).

If all these languages were tested on the same machine and CPU frequency, then the execution time is a good estimation of their power requirements.