Node.js vs C++ for mathematic

Pablosproject picture Pablosproject · Aug 30, 2012 · Viewed 27k times · Source

I have to write a server program that implements some fuzzy logic and I choose to write it in Node.js to take advantage of its event orientation. I have to work with difficult mathematic computational problem, and I don't know what's the best way to obtain performance:

  1. Write all in Node.js and use the power of the V8 engine for the mathematical task.
  2. Write a module in C++ that implements all the mathematical function and call it from Node.

Anyone that have experience in these type of computation on both platform?

Answer

Tobias Langner picture Tobias Langner · Aug 30, 2012

Since you need the Node.js part anyway, go ahead, implement everything in Node.js. If it is fast enough, this is easy enough to maintain. It's very hard to predict the power of a virtual machine / JIT compiler.

If it is not fast enough, first think about algorithmic improvements. If this doesn't help and if profiling shows that the computation is the problem, go ahead, re-implement it in C++. But be aware that writing performant C++ code is not trivial. Make sure that you have a good profiler at hand and measure often.

In general I'd say C++ code is faster if written correctly. The tricky part is to write it correctly. Please check this article Google Paper on C++, Java, Scala, Go for more information. The gist is - managed languages make it a lot easier to write & maintain the code but if you need raw performance, C++ is the best. But it comes at the price of needing a lot of expertise and that the code is harder to maintain.