I remember when PHP 7 was released. The first thing I did was a simple performance test. I don’t remember the script exactly, but it was similar to this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?php $time = microtime(true); $array = []; for ( $i = 0; $i < 10000; $i ++) { if (! array_key_exists ( $i , $array )) { $array [ $i ] = []; } for ( $j = 0; $j < 1000; $j ++) { if (! array_key_exists ( $j , $array [ $i ])) { $array [ $i ][ $j ] = true; } } } echo sprintf( "Execution time: %f seconds\nMemory usage: %f MB\n\n" , microtime(true) - $time , memory_get_usage(true) / 1042 / 1042 ); |
The results made me really happy. Memory usage was much lower and time execution had decreased a lot.
Recently, with the above script saved as “test.php”, I ran the test again, this time for multiple PHP version.
1
2
3
4
5
6
7
8
9
|
#!/usr/bin/env bash versions=( 5.6 7.0 7.1 7.2 ) for v in "${versions[@]}" do cmd= "docker run --rm -ti -v ${PWD}/test.php:/test.php php:${v}-alpine3.7 php -d memory_limit=2048M test.php" sh -c "echo ${v} && ${cmd}" done |
With the results:
5.6 Execution time: 2.428468 seconds Memory usage: 1332.009947 MB 7.0 Execution time: 0.601055 seconds Memory usage: 347.669807 MB 7.1 Execution time: 0.517198 seconds Memory usage: 347.669807 MB 7.2 Execution time: 0.470262 seconds Memory usage: 347.669807 MB
转载请注明:XAMPP中文组官网 » xampp performance increase from 5.6 to 7.2