Node.js vs Go 2014

It's been over a year since my last thoughts on the topic, so here's the 2014 update. Go 1.3 vs. Node 0.10.29.

Before we begin, please remember:

  • Previous thoughts/comparisons
  • These are some broad benchmarks. You should compare your own use cases, as well as factors such as developer experience, application purpose, and infrastructure.
  • These tests are intentionally not optimized. I use the bubble sort as an example of a language running several operations on the CPU. It would be useless to compare PHP's native sort() with JavaScript's, for example.

Alright, let's begin. Here's the good 'ole bubble sort, with some fixes people pointed out:

A chart comparing Go vs. Node's performance of the bubble sort algorithm

The results were as expected. Everything we already suspected about machine code vs. VM code has been shown to be true again. Because we are doing an operation that does pure CPU work and memory management, it is faster to use a language that compiles down to machine code, i.e. Go or C, than a language that runs in a virtual machine, such as Node.js's use of V8.

This should be considered when your application will do large amounts of computation in itself, rather than in a database layer. This depends on your use case, so there's a lot to consider, and your own use cases should be tested before deciding based on benchmarks.

But before we walk away and declare Go as the champion, let's remember the practicality of benchmarks.

Here's Go vs. Node.js running a simple MySQL query on a database with over 100k records.

A chart comparing Go vs. Node's performance of a MySQL query

There's a very slight difference here, and interestingly enough, Go and Node are really not doing 100% the same thing. Go is reading one row into an integer slot. Node is pulling all rows for BMW and stuffing it into an array.

If we add LIMIT 1 to the queries, we get Go averaging 86ms and Node.js 83ms. That's statistically insignificant.

Also, since everyone loves to hate on PHP, it's worth noting that PHP performed the original full query in 5241.53ms, tying it with the other two.

This is no surprise; the difference in application layers is negligible when the bottleneck of the application is the database or file system, which is usually the case.

So to conclude this year's post, I'll add on to what I said last year: Node and Go are both fast. Both have their purpose. If your absolute goal is code speed, Go will perform calculations and execute functions faster. If your application is well designed and relies on a database backend, Go, Node, and even Ruby and PHP will all perform similarly. In that scenario, I believe you should consider your or your team's preferences and abilities, above all else.

Hope this helps!