CPU Benchmark - single core speed test with Fibonacci Sequence in JavaScript
In this short article, I would like to show Fibonacci Sequence test that is run on a single core. The test source code was converted from C++ to JavaScript - check source article.
Example test.js
file:
let tmp, a = 0, b = 1;
console.log('Started!');
const t1 = Date.now();
for (let i = 0; i < 10000; ++i) {
for (let j = 0; j < 1000000; ++j) {
tmp = b;
b = a + b;
a = tmp;
}
}
const t2 = Date.now();
const dt = t2 - t1;
console.log('Finished!');
console.log(`Result: ${b}`);
console.log(`Time: ${0.001 * dt}s`);
Running with Node.js:
node test.js
Example output:
Started!
Finished!
Result: Infinity
Time: 17.531s
Notes:
Result: Infinity
printing is used only to prevent against automatic optimization.
Used Node.js: v14.16.0
Used OS: Windows 10 x64
Used PC:
- Ryzen 9 5900x
- DRR 4 (2x 32GB)
- Samsung SSD M.2 970 EVO (1TB)
- GeForce GTX 970 (4GB RAM)
Notes:
- same test for the first run under Node.js v16.13.0 took
18.430s
,- same test run few times under same Node.js instance returned
6.110s
- V8 made some optimisation.
See also
-
CPU Benchmark - Raspberry PI vs Banana PI - single core speed test with Fibonacci Sequence
-
CPU Benchmark - single core speed test with Fibonacci Sequence in Java
-
CPU Benchmark - single core speed test with Fibonacci Sequence in AssemblyScript
-
CPU Benchmark - single core speed test with Fibonacci Sequence in Dart
-
CPU Benchmark - single core speed test with Fibonacci Sequence in PHP