Save the planet! Program in C, avoid Python, Perl

As a former software engineer who’s mostly worked with C programming, and to a lesser extent assembler, I know in my heart that those are the two most efficient programming languages since they are so close to the hardware.

But to remove any doubts, a team of Portuguese university researchers attempted to quantify the energy efficiency of different programming languages (and of their compiler/interpreter) in a paper entitled Energy Efficiency across Programming Languages published in 2017, where they looked at the runtime, memory usage, and energy consumption of twenty-seven well-known programming languages. C is the uncontested winner here being the most efficient, while Python, which I’ll now call the polluters’ programming language :), is right at the bottom of the scale together with Perl.

The study goes through the methodology and various benchmarks, but let’s pick the binary-trees results to illustrate the point starting with compiled code.

binary-trees compiledTo the surprise of no one, the study concludes that “compiled languages tend to be, as expected, 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, and it’s even worse than languages relying on a VM like Java or Erlang, at least with the binary-trees sample used.

code efficiency VM

But the crown of the most inefficient languages goes to interpreted languages like Perl, Lua, or Python, and that’s by some margin.

interpreted languages poor efficiencyIt should be noted all 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. Considering MicroPyhon is now running on a wide range of microcontrollers, I suspect it may not be as bad on those platforms with a smaller footprint, and it would be interesting to find out the difference.

time memory energy programming languagesThe study also ranked each language with different combinations of objectives mixing time, memory, and energy parameters, and C is always at the top with those metrics. That’s been known for years, but if you want to optimize your program for battery life/low power, some of the routines would have to be optimized in C, assembler, SIMD instructions, or custom instructions for accelerators.

Via Hackaday

Share this:

Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress

Radxa Orion O6 Armv9 mini-ITX motherboard
Subscribe
Notify of
guest
The comment form collects your name, email and content to allow us keep track of the comments placed on the website. Please read and accept our website Terms and Privacy Policy to post a comment.
105 Comments
oldest
newest
Boardcon CM3588 Rockchip RK3588 System-on-Module designed for AI and IoT applications