问题
What would be the advantages, if any, of using a node.js addon written in C/C++ compared to calling a binary with arguments through child_process?
More specifically, I have a small program, which accepts possibly up to a few hundred arguments and returns a boolean.
回答1:
There is a huge difference.
C++ Addon is native code which is running as part of main application (on the same level as JS does). But if you use child_process, node will start new process and there is a huge overhead (spawning processes is much more complicated than running native code in one thread).
If you are deciding, which approach to use, it heavily depends on your situation. If you are familiar with C++ and you want to handle thousands of requests, you probably should consider writing an addon. But if you are writing a small app for personal use and your additional program is already functional as stand-alone app, I would use child_process and it can also provide great results with less effort.
来源:https://stackoverflow.com/questions/28267794/advantages-of-node-js-addon-vs-child-process