Analyzing energy consumption of CPython
Analyzing energy consumption of CPython
Python is one of the top three most popular programming languages globally, according to the latest Statista report. Big corporations widely use it to develop everything from web services to scientific computing applications. Its simplicity and high developer efficiency make it a top choice when creating backends and web applications. However, this convenience often comes with a trade-off – interpreted languages like Python are typically far less energy-efficient than compiled languages such as C++ or Rust.
A recent study by Rolf-Helge Pfeiffer from the IT University of Copenhagen investigated the energy consumption of different versions of CPython while running a server-side rendered web application to find the most energy-efficient one. The team designed and conducted a controlled lab experiment to address the study research question. The Otii Product Suite was a key tool for the results of the study -used to power up the entire system, as well as an automated energy measurement tool to collect recordings on voltage, current, and power consumption while running the server and managing clients interactions across multiple CPython version, including 3.8 to 3.13.
Intrigued about the study’s experiment and findings, we made an overview but we recommend checking out the complete research for a comprehensive understanding.
Why should we care about Python energy consumption?
With the massive adoption of Python in web services, data centers, and cloud applications, software engineers need to consider the environmental impact of their code. While Python boosts developer productivity, it’s no secret that interpreted languages generally lag behind compiled languages in energy efficiency. As systems scale, inefficiencies accumulate—so finding ways to optimize performance at every level is crucial.
It seems that the energy efficiency is of secondary interest for language designers and maintainers’, the team concludes from looking at the Python Enhancements (PEPs) and none of them being about energy efficiency.
That’s where this study comes into play. It finds ways of measuring system impacts and highlights the importance of monitoring energy consumption in today’s development workflows.
Practical experiment: Raspberry Pi + Otii Product Suite
The experiment used a Raspberry Pi (Model B+ V1.2) setup powered by the Otii Product Suite to record and further analyze the energy consumption of different CPython versions. It simulated real-world usage by running a server-side web application within the Raspberry Pi while three separate clients— also running on Raspberry Pi(s), interacted with the server through predefined, long-running scenarios. These scenarios mimicked typical user behaviors, such as loading pages, registering users, and sending data, making the experiment closely resemble actual application workloads.
The critical element of the study was keeping everything consistent—same web application, operating system, and webserver—across all test runs. The only changing variable was the version of CPython running the application, ensuring that any variations in energy consumption could be attributed solely to the differences in the interpreter versions.
As shown in the figure below, the Otii instrument, in this particular case, the Otii Arc Pro, was used to power up the Raspberry Pi but also to make precise measurements of power, current, and voltage consumption simultaneously.
In addition, to streamline the experiment across CPython versions, the Otii Automation Toolbox automatically handled the consumption data collection as the tests progressed—changing versions, from 3.8 to 3.13, one by one, after the established server-clients interaction had been completed for each version. For further details on the automation possibilities using this toolbox, see the examples for the different supported TCP clients.
With this comprehensive setup, Dr. Pfeiffer got an accurate and detailed analysis of how each version of CPython impacted energy usage, setting the stage for comparing energy efficiency without introducing any uncontrolled variables.
Most energy-efficient CPython version
Without going into the full depth of the study, here’s the core takeaway: CPython 3.12 has been shown to be the most energy-efficient version of the interpreter so far, cutting power consumption by over 8% compared to earlier versions. If you’re working on projects that depend on Python, upgrading to this version is definitely worth considering.
The study shows that the newer versions of CPython are not only faster but also greener. While performance optimizations often come with a power cost, CPython 3.12 delivers substantial energy savings without major downsides, striking a balance between speed and energy efficiency.
For those interested in the full scope of the study, including all the results and details of the experiments, it’s worth checking out the paper chapter to get a deeper understanding of how these improvements were measured and achieved.
Embracing energy efficiency in engineering
As engineers, we all play a part in reducing the carbon footprint of the tech we create. Whether we’re working on hardware or software, keeping energy efficiency in mind is important. Adopting a low-power mindset should be at the forefront of any project, no matter the field. It’s not just about squeezing out more battery life or minimizing power consumption—it’s about building smarter, more sustainable systems from the ground up.
In any embedded system or software development, paying attention to energy usage, even down to the milliamps, makes a real difference. Tools like the Otii Product Suite help by giving you a clear picture of how your design choices impact power consumption. Whether you’re optimizing an algorithm in code or tweaking hardware settings, having the ability to measure power in real time helps you make informed decisions that lead to more efficient systems.
Conclusion: Low power mindset
This study emphasizes the growing importance of energy efficiency in software engineering, particularly as sustainability becomes a key consideration in technology. With the proper tools, engineers can go beyond theoretical optimizations to gain precise, real-world insights into power consumption.
Looking forward, there’s plenty of room for further exploration. Dr. Pfeiffer’s team plans to extend their research by running the Python Performance Benchmark Suite on a variety of hardware platforms, including newer Raspberry Pi models and x86 architectures. Expanding the experiment could offer a broader perspective on energy efficiency across different hardware. There’s also potential to explore how other programming languages compare to Python, especially in the context of embedded systems.
By making energy efficiency a part of your development process from the start, you can build projects that last longer and use less power—whether it’s a small embedded device or a large-scale software system. It’s not just about saving energy—it’s about designing, having in mind the impact it will have in the future.
Become a member of our community
Gain access to exclusive resources, educational materials, and expert advice to enhance your knowledge and understanding of powering IoT devices and battery testing.