A small synthetic test.
for (var i = 0; i < 1e9; i++) {
}
Node.js v13.11.0: 440ms
njs@e6d5690: 17008ms
Just wondering, why such a difference?
CentOS 8 Linux 4.18.0-80.el8.x86_64, 4GB RAM, Intel Core [email protected]
@vryabinin
Just wondering, why such a difference?
node.js uses V8 which compiles JS code into the native x86.
njs is an interpreter (like CPython implementation of python).
See for the reference https://bellard.org/quickjs/bench.html
The conclusions are:
@vryabinin
Also, constant expressions are not optimized, it's better to avoid them in a loop.
$ cat y.js
console.time(1);
for (var i = 0; i < 1e9; i++) {
}
console.timeEnd(1);
console.time(2);
for (var i = 0; i < 10**9; i++) {
}
console.timeEnd(2);
$ njs y.js
1: 13975.273739ms
2: 66203.931495ms
$ node y.js
1: 855.346ms
2: 863.493ms
Most helpful comment
@vryabinin
node.js uses V8 which compiles JS code into the native x86.
njs is an interpreter (like CPython implementation of python).
See for the reference https://bellard.org/quickjs/bench.html
The conclusions are: