I recently purchased a $5 VPS from Vultr and what I get is 1 core (2.4GHz), 740MB RAM and 15GB SSD. It is the basic (minimal) specs and nothing compared to my luxury VPS from QuickHostUK, where my VPS is 6 cores (2.4GHz), 3GB RAM, 50GB SSD.
I have legacy PHP code and that is why I hold on on upgrading to Ubuntu 16.04 and PHP7.x but suddenly I thought it will be interesting to compare the performance between PHP7.0 (Ubuntu 16.04) and PHP5.6 (Ubuntu 14.04).
PHP Benchmark Code
The following is the code that translated from this post. It is to compute the prime numbers up to N.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | define('N', 1000000); $Primes = array(); $Primes[0] = false; $Primes[1] = false; for ($i = 2; $i <= N; $i ++) { $Primes[$i] = true; } $M = sqrt(N); for ($j = 2; $j <= $M; $j ++) { if ($Primes[$j]) { $i = $j * $j; while ($i <= N) { $Primes[$i] = false; $i += $j; } } } $s = ''; for ($i = 0; $i < N; $i ++) { if ($Primes[$i]) { $s .= $i . " "; } } echo md5($s); |
define('N', 1000000); $Primes = array(); $Primes[0] = false; $Primes[1] = false; for ($i = 2; $i <= N; $i ++) { $Primes[$i] = true; } $M = sqrt(N); for ($j = 2; $j <= $M; $j ++) { if ($Primes[$j]) { $i = $j * $j; while ($i <= N) { $Primes[$i] = false; $i += $j; } } } $s = ''; for ($i = 0; $i < N; $i ++) { if ($Primes[$i]) { $s .= $i . " "; } } echo md5($s);
VPS Comparisons
Here is the PHP version from Vultr VPS.
Here is the PHP version from QuickhostUK VPS.
PHP Code Execution Performance between 5.6 and 7.0
Now, let’s run the benchmark php script to see how long it takes on both VPS (remember PHP7.0 VPS has only 1 core and 740RAM but PHP5.6 VPS has 6 cores and 3GB RAM).
That surprised me a little bit!
PHP7.0 outperforms the PHP5.6 up to almost 12 times faster! Click To Tweeteven the PHP5.6 is possible to use more cores and more RAM. Both CPUs are the same clock speed (2.4 GHz). I have run the code multiple times to confirm the consistency of the comparisons.
Update: I have upgraded QuickHostUK to Ubuntu 16.04 + PHP 7.08 and run the test on the same Instance, here is the result:
1 2 3 | real 0m1.191s user 0m0.464s sys 0m0.726s |
real 0m1.191s user 0m0.464s sys 0m0.726s
Still pretty good improvements with PHP7 (around 3 times faster). However there is a chance that PHP7.0.11 gives more speedup than PHP7.0.8.
This is just tiny simple example (with majorly the integer computation), not to mention some other complex and time-consuming code in modern websites e.g. WordPress. If you have not used PHP7.x yet, start using it then!
–EOF (Coding For Speed) —
loading...
Next Post: Integer Performance Comparison for C++, C#, Delphi