Jonathan Warner

Benchmarks: Node.js vs Go 1.1

Following the success of my last Go vs. Node post, I've received requests to repeat the tests with Go 1.1 and Node 0.10. The same rules apply here as last time; take these with a lattice of Sodium Chloride, as the benchmarks tell us information, not answers.

Without further ado, here's a simple Bubble sort. Yes, we're using a bubble sort because it is intentionally inefficient and pushes the language to make several unnecessary calculations. It would not be fair to compare the two's native sorting algorithms, as this would not be a direct comparison.

Time taken to complete 1,000,000 bubble sort operations. Lower is better.

Go wins the test, but note the huge difference between the mean and the best; Go has a very large standard deviation in the data set, and did in all the cases I repeated the test. I'm really not sure why this is.

It is observed that Go continues its dominance when handling raw HTTP requests. I will note, though, that upon increasing the concurrency from 100 to 1000, Go spikes erratically, with some tests as high as 10k requests per seconds, and others as low as 6k, with no clear pattern. Since I was not able to replicate these results consistently, I'm leaving this as an observation only.

Bottleneck: Redis

I wanted to experiment with some bottlenecks, because rarely would one be relying purely on the host language to handle a complete request. In most cases, a central database will be a very large and annoying bottleneck in an application.

For this reason, I wanted to see how the two stacked up when connecting to a Redis backend.

Now that is interesting. Go experiences better response time, but increases at a faster rate than Node.js, crossing over at around 5.2k requests. The difference after that point is small, but perhaps not negligible.

Again, it's worth noting Go showed variance between 4k and 7k request per second, whereas Node.js scored 4.8k to 4.9k in nearly every sample. Given that, I highly recommend benchmarking the two, even with sample code like this, on your own machine with your own configuration.

Conclusion

I refuse to draw any conclusions, because again, benchmarks should not be the determining factor. I will, however, state that Go 1.1 continues to outpace Node.js, and even the HTTP layer seems to have been 1-upped now. However, when a bottleneck is added, the two perform with a much smaller gap, leading to more evidence that the two should be compared based on use-case and preference, not purely benchmarks.

It is also my anecdotal experience in these tests that Node seems to handle increasing loads more linearly than Go, but this is something that will almost entirely depend on the use case itself.

Any questions, suggestions, or better points are welcomed (and encouraged)