I briefly tested these three engines (rhino/spidermonkey/v8) with the following simple program:
function p(n) {
for (var i = 2;i * i <= n;i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
var sum = 0;
for (var k = 2;k < 10000000;k++) {
if (p(k)) {
sum++;
}
}
print(sum);
And get the following results:
$ time rhino -O 9 sample.js
664579
real 0m40.495s
user 0m40.793s
sys 0m0.180s
$ time js sample.js
664579
real 0m9.465s
user 0m9.477s
sys 0m0.000s
$ time d8 sample.js
664579
real 0m8.941s
user 0m8.943s
sys 0m0.000s
While spidermonkey and v8 are generally comparable in speed, rhino takes significantly longer time even with the highest level of optimization. Is anything wrong here?
I've surveyed standard JavaScript benchmarks but most of them run the test in browser. Could anyone please recommend a command-line version to test the core engines?
While spidermonkey and v8 are generally comparable in speed, rhino takes significantly longer time even with the highest level of optimization. Is anything wrong here?
Nothing wrong here. Rhino is just slow, that's it.
I've surveyed standard JavaScript benchmarks but most of them run the test in browser. Could anyone please recommend a command-line version to test the core engines?
Source codes of Sunspider, Kraken and Octane (ex. v8 test suite; it is included in the V8 engine's sources) benchmarks are available, so you can easily perform standalone testing in the command line.