Python vs. Go: performance

My story notwithstanding, let’s get down to the business of comparing Python and Go.

Runtime performance

First, let’s focus on performance as it’s usually understood: performance at runtime. Which language runs faster?

There’s no two ways to say this: Go runs faster than Python, in some use cases even 30 times faster.

In computer language benchmarks, Go finishes the mandelbrot test 48x faster, spectral-norm 43x faster, and n-body 38x faster.

Golang’s built-in support for concurrency also helps it finish calculations faster compared to Python.

But for many use cases, runtime performance may not matter that much because very often the language is just the glue between the app and the database.

Which brings us to another way to think about performance.

Developer productivity

Runtime performance may be important for some apps, but there's another metric that applies to any software project: your developers’ productivity.

Ultimately, you want to meet your project deadlines and get your code live where it can benefit end users. For most apps, this will be more important than whether some function executes within 10 ms or 100 ms.

So which development team will get faster results, one working with Python or one working with Go?

The obvious answer is “it depends,” but let’s have a closer look at which aspects of Python and Go will influence the results.

Python’s advantage: tons of frameworks and libraries

Python is well-known for its rich selection of frameworks and tons of useful libraries, helping developers get any project off the ground much faster.

From “batteries included” offerings like Django to more “minimalist but expandable” frameworks like Flask, Python will give your dev teams a running start in almost any situation.

It gets even better when you look at Python’s legendary roster of libraries:

Numpy for array handling and complex matrix functions,

for array handling and complex matrix functions, Tensorflow and scikit-learn for deep learning,

and scikit-learn for deep learning, OpenCV for image processing,

for image processing, Pandas for data analysis,

for data analysis, matplotlib for visualization,

for visualization, and the list goes on.

Being a younger language, Golang hasn’t had the time to accumulate such an impressive offering of pre-built solutions yet.

But that’s not to say that Golang doesn't have anything to offer. Here are a few examples of Golang frameworks:

Gin (currently the most popular with 26k stars on GitHub),

(currently the most popular with 26k stars on GitHub), Echo (13k stars),

(13k stars), Revel (11k stars).

Golang’s advantage: simplicity

On stream.io’s blog, Thierry Schellenbach mentions why Stream made the switch from Python to Go. One of the reasons was that Go offers a certain simplicity, it doesn’t let you get so “creative” with the code you’re writing.

In Python, the case is rather the opposite. For example, with Python you can:

use MetaClasses to self-register classes upon code initialization;

swap out True and False;

add functions to the list of built-in functions;

overload operators via magic methods;

use functions as properties via the @property decorator.

The question is: do you need these advanced features to deliver functional code?

In most cases, you don’t. And that’s to Golang’s advantage.

Go developers keep it simple—they almost have no other choice—so their code will be easier to understand when it changes hands. And when programmers can understand each other’s work at a glance, they can make changes faster, and productivity rises.