Join us at TNW Conference 2022 for insights into the future of tech →

The heart of tech

Python sucks in terms of energy efficiency — literally

C is the greenest

Python sucks in terms of energy efficiency — literally
Ivan Mehta
Story by

Ivan Mehta

Ivan covers Big Tech, India, policy, AI, security, platforms, and apps for TNW. That's one heck of a mixed bag. He likes to say "Bleh." Ivan covers Big Tech, India, policy, AI, security, platforms, and apps for TNW. That's one heck of a mixed bag. He likes to say "Bleh."

Python is one of the most popular programming languages in the world. Dutch software company’s programming language index for 2021 also indicates that.

But is it one of the most energy-efficient coding languages out there? Not really. A study from researchers of Universidade do Minho, Portugal (first spotted by hackaday) says that Python is just better than Perl in terms of energy consumed while performing certain tasks. It notes that C tops the chart followed by Rust, C++, and Ada.

Researchers used 10 popular algorithms from the Computer Language Benchmarks Game (CLBG), to measure the energy consumption, runtime, and memory usage of 27 well-known coding languages. You can check out the results in the table below:

Comparing energy consumption, time, and memory used by different programming languages
Comparing energy consumption, time, and memory used by different programming languages

It’s pretty clear that Python performs poorly in terms of time and memory.

Now you might argue that this study is from 2017, and a lot has changed since then, you’re right. So the researchers have published another study with updated tests and results earlier this year. Spoiler alert: Python still performs poorly.

In these extended tests, researchers established a co-relation between DRAM energy consumption, peak memory, and total memory used during the execution.

The team also performed a set of standard algorithms along with a few tests from Rosetta Code, a site to compare different programming languages’ execution of common algorithms. You can check out the tables below; Python is mostly in the bottom half of rankings when it comes to energy consumption. It couldn’t even complete the Fibonacci task in 24 hours of the cut-off time.

So it’s evident that languages like Python, Perl, and Ruby are not really energy efficient. On the other hand, C, C++, and Rust are some of the greenest languages of the lot.

You can read more about the study and the method used to evaluate this result here.