Performance

What if your primary concern is speed? In this day and age, it seems performance optimizations are more important than ever. People don’t like to wait for information. In fact, 40% of users will abandon your site if it takes longer than 3 seconds to load.

Node is often touted as a highly performant because of its non-blocking asynchronous I/O. Also, as I mentioned before, Node is run on Google’s V8 engine which was optimized for dynamic languages. Go on the other hand was designed with speed in mind. The developers at Google achieved this by building “an expressive but lightweight type system; concurrency and garbage collection; rigid dependency specification; and so on.”

To compare the performance of Node and Go, I ran a couple of tests. These focus on the rudimentary, low-level abilities of the languages. If I had been testing something like HTTP requests or time-intensive processes, I would have used Go’s language-level concurrency tools (goroutines/channels). Instead, I stuck to basic features of each language (see Concurrency in Three Flavors for a deeper look into goroutines and channels).

I also included Python in the benchmarks so we feel good about the Node and Go results no matter what.

Loop/Arithmetic

Iterating through a billion items and adding them up:

Node

Go

Python

Results

The clear loser here is Python clocking in at over 7 seconds. On the other hand, both Node and Go were extremely efficient, clocking in at 900 ms and 408 ms, respectively.

Edit: As some of the comments suggest, Python’s performance could be improved. The results have been updated to reflect those changes. Also, the use of PyPy greatly improves the performance. When run using Python 3.6.1 and PyPy 3.5.7, the performance improves to 1.234 seconds, but still falls short of Go and Node.

I/O

Iterating over 1 million numbers and writing them to a file:

Node

Go

Python

Once again, Python is third at 7.82 seconds. The gap between Node and Go is quite large in this test with Node taking about 1.172 seconds and Go taking 213 ms. What is really impressive though is that the majority of Go’s processing time is spent compiling. If we compile the code via go run down into a binary, the I/O task only takes 78 ms — more than 15 times faster than Node.

Edit: Changed Go code to implement buffered I/O.

Bubble Sort

Iterating 1 million times over a 10-item array and sorting:

Node

Go

Python

Results

As usual, Python’s performance was the poorest, completing the task at hand in about 15 seconds. Go was able to finish the task over sixteen times faster than Node.

Verdict

Go is the clear winner in all three tests, but Node, for the most part, performs admirably. And Python was there, too. To be clear, performance isn’t everything when choosing a programming language. If your application doesn’t need to process high amounts data, then the differences in performance between Node and Go may be negligible. For some additional comparisons on performance, see the following: