EN
CPU Benchmark - single core speed test with Fibonacci Sequence in PHP
8
points
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 PHP - check source article.
Example test.php
file:
<?php
$a = 0;
$b = 1;
echo "Started!\n";
$t1 = floor(1000 * microtime(true));
for ($i = 0; $i < 10000; ++$i) {
for ($j = 0; $j < 1000000; ++$j) {
$tmp = $b;
$b = $a + $b;
$a = $tmp;
}
}
$t2 = floor(1000 * microtime(true));
$dt = $t2 - $t1;
echo "Finished!\n";
echo "Result: " . $b . "\n";
echo "Time: " . (0.001 * $dt) . "s\n";
Running with PHP:
php test.php
Example output:
Started!
Finished!
Result: INF
Time: 95.515s
Notes:
Result: INF
is printed only to prevent against automatic optimization.
Used PHP:
PHP 8.2.10-2ubuntu1 (cli) (built: Sep 5 2023 14:37:47) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.2.10, Copyright (c) Zend Technologies
with Zend OPcache v8.2.10-2ubuntu1, Copyright (c), by Zend Technologies
Used OS: Ubuntu 23.10 x64
Used PC:
- Ryzen 9 5900x
- DRR 4 (2x 32GB)
- Samsung SSD M.2 970 EVO (1TB)
- AMD Radeon RX 6700 XT (12GB RAM)
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 JavaScript