Why Google\'s V8 JavaScript engine in my C++ addon works significantly slower than in Node.JS?
I\'ve tried to write some stupidly simple code for generating prime nu
In the C++ version all variables declared in the script source (result
, primeNumberCounter
, i
, j
, isPrime
, start
, end, time
) are global because script's top level scope is global scope.
For optimizing compiler it is easy to allocate local variables into machine registers (or spill slots on stack) and keep track of their type. Working with global variables on the other hand requires constant memory accesses and type checks because V8 does not (currently) perform a register promotion optimization.
If you wrap the source into an immediately called function difference should go away.