简体   繁体   中英

NodeJS c++ addon performance

With NodeJS 0.11 it is possible to add custom c++ code, compile it with V8 and require it as a module.

When doing a lot of math in the c++ addon, would that be a lot faster then 'native' javascript?

Probably, but it depends on the math. Even if you use c++, the elapsed time for the computation might be too long and you'll end up blocking the main node loop thereby degrading system performance. Depends on your hardware and the size and nature of the computation.

Look at performing the computation in a worker thread. This way, you can leverage multiple cores/CPUs, and no matter how long the math takes, you won't block the main loop. The node cluster function might help here. If you decide to use a C++ addon, then you also can look at the libuv functions, in particular uv_queue_work .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM