Python is 57x slower than C++ (and 45x worse for the planet)

trading systems algo trading using C++ and Python

Banks and other financial institutions like to make a big deal about their environmental efforts through their ESG teams, but that doesn’t mean they’re climatically benign. Their engineering teams are generating big emissions merely through the code they write.

A 2017 paper published alongside the ACM SIGPLAN Engineering Language Conference tested a number of the most prevalent programming languages in use today to determine, among other things, how much energy they used. The results showed that Python, despite its popularity was a massive energy hog using 45 times as much energy (4390 joules) as C++ (77 joules) to execute its programs.

MISSING: summary MISSING: current-rows.
C 57 2,019
Rust 59 2,103
C++ 77 3,155
Ada 98 3,740
Java 114 3,821

MISSING: summary MISSING: current-rows.
Perl 4,604 132,856
Python 4,390 145,178
Ruby 4,045 119,832
Lua 2,660 167,416

Python is an interpreted language. While compiled languages like AdaC++ and Rust directly translate to instructions for the machine, Python must be read by a separate program first before being translated into machine instructions. Interpreted languages are generally far easier to learn and simpler to use, but this comes at the cost of energy in a big way.

Python is very well-loved in finance. Investment firm Man Group for example have called it the “second language” of the firm. On eFinancialCareers, of the 5,072 jobs currently available for quants and technologists, 1217 mention Python. If not Python, most banks like using alternative interpreted languages; Goldman Sachs’ love affair with Slang, is well documented.

The same phenomenon can also be seen in fintechStripe, for example, relies heavily on Ruby, which is only narrowly faster than Python. If this evident energy gap exists in small, optimized benchmarking programs, one can only imagine how much additional energy is produced in Stripe’s 50 million lines of code.

C++ may be kind on the environment, but it is far from kind on its developers. C++ is very difficult to work with by nature, which is what makes its elite engineers so valuable to hedge funds and high frequency trading firms. Rust, on the other hand, is similarly energy efficient, but is known for being a lot more enjoyable to work with. However, it lacks a serious presence in finance beyond some crypto roles.

The most peculiar phenomenon is Java. The only language in the top five for energy consumption not to be a pure-compiled language. While it is somewhat low level and capable of ultra low-latency code, Java also operates using the Java Virtual Machine (JVM) which makes it much easier for developers to work with.

Original Source: Python is 57x slower than C++ (and 45x worse for the planet)