Reputation: 41
I have figured out that the latest released node(v8.3.0) runs much slower than an older version(v6.10.1) by running this simple test code (test.js):
var c = 10000*10000;
var t = 0;
for (var i = 0; i < c; ++i) {
t += i;
}
console.log(t);
Both versions of node projects were configured and built by these commands:
ns$ ./configure --debug --gdb; make
The test code above was executed for several times by both of the node binaries(release version) built above in this way:
ns$ time node test.js
For each time, the results looked like:
For v6.10.1:
real 0m0.198s
user 0m0.188s
sys 0m0.004s
For v8.3.0:
real 0m0.488s
user 0m0.456s
sys 0m0.020s
I have learned that node v8.3.0 was integrated with the newer version of v8 engine which is said has higher performance, so I supposed that the new version of node should at least run as fast as the old one. But the test results(almost three times slower) told me I was totally wrong! Does anyone know why?
Upvotes: 3
Views: 114
Reputation: 203304
Aside from the new JIT compiler not being a generic "everything will run faster" improvement, there's also a flaw in your testing methodology: you're timing externally, which also counts runtime setup and other one-time costs that aren't a good measure of any speed improvement of the interpreter itself.
I ran the following benchmarking suite (using benchr
, a benchmark runner that I wrote):
suite('loops', () => {
benchmark('var', () => {
var c = 10000*10000;
var t = 0;
for (var i = 0; i < c; ++i) {
t += i;
}
});
benchmark('let', () => {
let c = 10000*10000;
let t = 0;
for (let i = 0; i < c; ++i) {
t += i;
}
});
});
I'm benchmarking both var
and let
to show one of the speed improvements of Node.js v8. I ran the benchmark using Node.js v6.11.2 and v8.3.0.
The results:
# v6
✔ var 11.13 ops/sec ±0.92% (32 runs) fastest
✔ let 3.72 ops/sec ±0.87% (14 runs) -66.56%
# v8
✔ var 11.08 ops/sec ±1.11% (32 runs)
✔ let 11.11 ops/sec ±1.26% (32 runs)
Some simple conclusions:
node
executable to the time it starts running the code) for v8 is a bit higher than for v6let
in v6 is substantially slower than var
var
(the timing differences are within the error margins)As for the last point: I doubt that a main objective of the new JIT compiler was to improve event-loop-blocking code like this.
EDIT: I thought it'd be useful to also add the results for v8.2.1:
✔ var 11.09 ops/sec ±1.11% (32 runs) fastest
✔ let 0.86 ops/sec ±0.77% (7 runs) -92.21% # 😱
Upvotes: 1