https://www.cnx-software.com/2021/11/18/save-the-planet-program-in-c-avoid-python-perl/ Skip to content CNX Software - Embedded Systems News CNX Software - Embedded Systems News News, Tutorials, Reviews, and How-Tos related to Embedded Linux and Android, Raspberry Pi, Arduino, ESP8266/ESP32, Development Boards, SBC's, TV Boxes, Mini PCs, etc.. Wisblock modular IoT systemWisblock modular IoT system Menu * About + About + Contact Us + Advertisement & Consulting Services + Work for Us + Support CNX Software + Privacy Policy * All News * Raspberry Pi * Arduino * Reviews * Tutorials * Shop Posted on November 18, 2021 by Jean-Luc Aufranc (CNXSoft) - 20 Comments on Save the planet! Program in C, avoid Python, Perl 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 compiledbinary-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 VMcode 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 efficiencyinterpreted 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 languagestime 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 jean-luc aufranc cnxsoftjean-luc aufranc cnxsoft Jean-Luc Aufranc (CNXSoft) Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011. Share this: Support CNX Software! Donate via PayPal or cryptocurrencies, become a Patron on Patreon, or buy review samples TagsC/C++, java, low power, programming, python Related posts: 1. What Programming Language Should I Learn ? 2. The Eclipse Foundation Releases Open Source Smart Home & IoT Gateway Frameworks, MQTT & oneM2M Implementations 3. Top Programming Languages & Operating Systems for the Internet of Things 4. Eclipse IoT Survey Report Reveals Arm & Linux Dominate, Security Concerns 5. LinuxCon 2011 Presentation: Introduction to Python Programming Language Connect with: FacebookFacebook GoogleGoogle TwitterTwitter Subscribe Login Notify of [new follow-up comments ] [ ] [>] guestguest Label[ ] {} [+] [ ] [ ] Name* [ ] Email* [ ] Website [ ] I agree to the Privacy Policy 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. [ ] [Post Comment] guestguest Label[ ] {} [+] [ ] [ ] Name* [ ] Email* [ ] Website [ ] I agree to the Privacy Policy 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. [ ] [Post Comment] 20 Comments oldest newest nicknick nick 9 hours ago C is probably the most dangerous language - did the researchers factor in the amount of downtime and damage caused by badly written C that crashes. Reply dgpdgp dgp 8 hours ago nick I'm not going to claim that C is perfect or anything but whatever language you use it runs on the same machine. If the machine allows for badness it will eventually happen whether you use so called safe languages or not. I think a lot of new languages introduce issues of their own. You might be avoiding stupid memory errors (which we have lots of tooling to find and debug now even for C) but now you're adding a ton of untrustable code from the built in package manager. Why bother searching high and low for a memory error you... Read more >> Reply Frank EarlFrank Earl Frank Earl 7 hours ago dgp Bingo! Reply Frank EarlFrank Earl Frank Earl 7 hours ago nick Badly written code shouldn't count into things. Trying to protect people from themselves is where a good part of those inefficiencies come from. There's something called, "skill," that needs to be accounted for. SERIOUSLY. I don't want something with a safety net because it leads to devs being sloppy. Reply MeeMee Mee 9 hours ago Seems like Rust should be the "go to" language if you want speed, efficiency and safety. Reply Frank EarlFrank Earl Frank Earl 7 hours ago Mee No, because it's got complex constructs that are hard to follow, etc. The problem with Rust is that it's trying to do the same things that the latest C++ standards are doing coupled with what Haskell does well (The efficiency in Rust comes at other prices)- with i's own new syntax and ROE that do not give you the same things. Reply SanderSander Sander 8 hours ago The low-energry consumption of C/C++ became only relevant when programs moved from client side to provider/cloud ... because only then the provider had to pay himself for the energy consumed. That caused a raise in popularity in C/C++ in the past 1-2 past decade. Reply Frank EarlFrank Earl Frank Earl 7 hours ago Sander It actually came into play much earlier on. The notion that C/C++ wasn't popular prior to this and all is a silly notion out of box. You just came late to the party. That's what over 35 years in the industry brings you. Comprehension. Of a lot of things. Reply dgpdgp dgp 8 hours ago I haven't read the whole thing but based on your write up I'm sceptical that there is any realworld insight to be gained. Even in the highlevel VM based languages like java you wouldn't be writing these micro functional blocks in the language itself as you should have decentish compiled versions of those things provided already. Otherwise what's the point? Python is basically hot glue over C libraries in a lot of cases. I doubt it makes a huge amount of difference for a lot of use cases. And the use case for these languages tends to be different too..... Read more >> Reply Frank EarlFrank Earl Frank Earl 7 hours ago dgp It's somewhere between their take and yours. Seriously. It's premature optimization for most cases, to be sure- but there's a lot more done in Perl and Python than ought to be and I consider some of the inefficiencies they "measured" to be a lack of comprehension of the language and proceeding to implement something as if you'd do it in C. Lua's not that inefficient, for example- you couldn't use it in games as a scripting language, for example, if it were as "bad" as they're describing there. Some of that you talk to- but you kind of gloss it... Read more >> Reply Frank EarlFrank Earl Frank Earl 7 hours ago Frank Earl The closer you get to C in that hierarchy there in their study, the more efficient you got. This doesn't get into the relative merits or issues (and there ARE in many of them) of the various languages. They just proceeded to implement and then tested it, without contemplation of the features of the languages in question. After having learned, and professionally used over 20 programming languages over the 35+ years in the industry, there's good choices, good fits and poor ones. Both in terms of developer efficiency, system efficiency, scale out, etc. It's a bit of an indication... Read more >> Reply dgpdgp dgp 7 hours ago Frank Earl >inefficiencies they "measured" to be a lack of comprehension of the language Or they knew that but the findings would be much less *interesting* if they benchmarked a full real world app written in C against basically the same app implemented as Python glue over mostly the same C libraries. Reply TimTim Tim 6 hours ago dgp I tend to agree. We have always done UI in VB because it's painless, and everything else in C or assembler. Reply Codrut RCodrut R Codrut R 6 hours ago but this means killing of poetry... as latin, as Perl... Reply Tuff ProTuff Pro Tuff Pro 5 hours ago How did Go used so much CPU? There is something wrong there because every script i did in Go had a good CPU and memory usage. Reply ClownWorldClownWorld ClownWorld 2 hours ago Tuff Pro Compared to what? Reply Marcin DabrowskiMarcin Dabrowski Marcin Dabrowski 1 hour ago Tuff Pro So is Rust's, there have been discoveries of rather substantial improvements to such common algorithms, but they are not so obvious and I doubt that they are all in there. As for Go, this is often cited: https://blog.discord.com/ why-discord-is-switching-from-go-to-rust-a190bbca2b1f Reply chungachunga chunga 5 hours ago Waouh, that means low level programming languages are more efficient than higher level ones...just kind of wheel re-discovery uh... Nothing about assembly language which should relegate C and C++ to the summits of inefficiency, and why not go to hexa code or directly in binary...good luck to program even if only a simple compression software. Maybe you should consider only the global cost of development, which is currently the only items all companies are focusing on. Yeah, develop a complex software in C, at the good level of security and user friendly, will be 5 times longer than in python. ... Read more >> Reply Scott LambScott Lamb Scott Lamb 11 minutes ago A key point about this study: it's not a direct comparison of programming languages. It's a comparison of implementations of The Computer Language Benchmarks Game challenges in a variety of programming languages. Some of the implementations are painstakingly optimized with SIMD and sophisticated algorithms. Some aren't. It's benchmarking N different programs written in M languages (where M> Reply tkaisertkaiser tkaiser 2 seconds ago Scott Lamb The usual 'casual benchmarking: you benchmark A, but actually measure B, and conclude you've measured C' Reply Advertisement Post navigation Previous PostPrevious Photon Mono X resin 3D printer review with Wash and Cure Plus Machine - Unboxing and First Prints Search for:[ ]Search Button Tiger Lake H Xeon W COM Express moduleTiger Lake H Xeon W COM Express module Trending Posts - Last 7 Days * Orange Pi R1 Plus LTS is a cheaper dual GbE SBC with YT8531C Ethernet transceiver 4.9k views | 7 comments * Experiences of configuring and using a 'hackendeck' homemade Steam Deck 4.8k views | 10 comments * Save the planet! Program in C, avoid Python, Perl 3.7k views | 19 comments * Android 12 on Raspberry Pi 4 - (Almost) everything works 3.3k views | 10 comments * How to flash firmware to Rockchip devices in Windows and Linux (2021 Edition) 2.5k views | 10 comments SPONSORS Gateworks rugged industrial IoT SBCGateworks rugged industrial IoT SBC UGOOS products 2021UGOOS products 2021 RK3399Pro SBCRK3399Pro SBC DS03 digital signageDS03 digital signage Station M2 Geek ComputerStation M2 Geek Computer Advertisement Recent Comments * tkaiser on Save the planet! Program in C, avoid Python, Perl * Scott Lamb on Save the planet! Program in C, avoid Python, Perl * SuZet on Orange Pi R1 Plus LTS is a cheaper dual GbE SBC with YT8531C Ethernet transceiver * Marcin Dabrowski on Save the planet! Program in C, avoid Python, Perl * ClownWorld on Save the planet! Program in C, avoid Python, Perl Subscribe to Comments RSS Feed Advertisement Latest Reviews * Anycubic Mono X resin 3D printer reviewAnycubic Mono X resin 3D printer reviewPhoton Mono X resin 3D printer review with Wash and Cure Plus Machine - Unboxing and First Prints Hey, Karl here. Today we are going to unbox and take a look at Anycubic's Photon Mono X resin 3D printer and [...] * hackendeckhackendeckExperiences of configuring and using a 'hackendeck' homemade Steam Deck Valve recently released information about developing for the Steam Deck if you didn't have a Dev-Kit which is [...] * Zidoo M6 rockchip firmware updateZidoo M6 rockchip firmware updateHow to flash firmware to Rockchip devices in Windows and Linux (2021 Edition) We've written several articles detailing methods to flash firmware to Rockchip devices in Windows or [...] Follow CNX Software on Google NewsFollow CNX Software on Google News Email subscriptionEmail subscription Copyright 2021 - CNX Software Limited Privacy Policy This website uses cookies to improve your experience. We'll assume you're ok with this, but if you don't like these, you can remove them Accept Privacy & Cookies Policy Close Privacy Overview This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience. Necessary [*] Necessary Always Enabled Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information. Non-necessary [*] Non-necessary Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website. SAVE & ACCEPT wpDiscuz [ ] Insert