3v4l.org

run code in 300+ PHP versions simultaneously
<?php // This is a proof-of-concept for the PHP-Memory-Bug. // This is a well known PHP-Behavior, this script will test if this bug // can be solved using "array-key-recycling". // Switch this to proof //$bLinear = FALSE; // Array-Keys are recycled $bLinear = TRUE; // Array-Keys just increment -> Bug! // Some Constants $loops = 1000; $start = 0; $size = 1000; $payload = "testing..."; $mem_limit = "5M"; // Set Memory-Limit, define memory_get_usage for older versions ini_set("memory_limit",$mem_limit); if(!function_exists("memory_get_usage")){ function memory_get_usage() { $output = Array(); $pid = getmypid(); exec("ps -o rss -p $pid", $output); return $output[1] *1024; } } // Output-Function function sEcho($message = ""){ echo date("d.m.Y H:i:s")." ".number_format(memory_get_usage())." ".$message."\n"; } sEcho("Starting"); // Main loop for($k=0;$k<$loops;$k++){ // Recycle or use new array-key $multiplier = 1; if($bLinear) $multiplier = $k; // Get some Data - i.e. from MySQL $arData = Array(); sEcho("filling ".$k); for($i=$start*$multiplier;$i<($size*$multiplier)+$size;$i++){ $arData["a"][$i]["c"] = $payload; $arData["b"][$i]["d"] = $payload; } sEcho("filled ".$k); // Do Some Stuff... // Free data again unset($arData); // This will not free the used array-keys. sEcho("unset ".$k); } sEcho("Done");

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
7.2.00.0040.01121.56
7.1.70.0030.01319.25
7.1.60.0100.02319.40
7.1.50.0210.01837.11
7.1.00.0070.07324.36
7.0.200.0290.00618.91
7.0.140.0070.07724.23
7.0.90.0670.08022.98
7.0.80.0670.05022.89
7.0.70.0770.07322.84
7.0.60.0800.09022.91
7.0.50.0870.09023.34
7.0.40.0000.08320.14
7.0.30.0070.04720.13
7.0.20.0030.05320.12
7.0.10.0070.08320.13
7.0.00.0170.07720.09
5.6.280.0100.09325.75
5.6.240.0100.11325.28
5.6.230.0030.07325.23
5.6.220.0130.07325.18
5.6.210.0070.10025.19
5.6.200.0170.09725.61
5.6.190.0030.06025.79
5.6.180.0070.07725.66
5.6.170.0130.09025.66
5.6.160.0000.05025.68
5.6.150.0130.09725.67
5.6.140.0130.09325.75
5.6.130.0030.11325.66
5.6.120.0070.09325.71
5.6.110.0100.10025.75
5.6.100.0100.07025.69
5.6.90.0030.08725.71
5.6.80.0070.09725.10
5.6.70.0070.06725.12
5.6.60.0070.10025.04
5.6.50.0130.05025.05
5.6.40.0130.10725.03
5.6.30.0100.09725.13
5.6.20.0070.06724.96
5.6.10.0070.10325.02
5.6.00.0070.11025.04
5.5.380.0130.05025.02
5.5.370.0100.09324.96
5.5.360.0000.06325.09
5.5.350.0100.09324.94
5.5.340.0130.08725.48
5.5.330.0070.05725.46
5.5.320.0070.06325.54
5.5.310.0030.11025.44
5.5.300.0030.09725.58
5.5.290.0170.06725.55
5.5.280.0100.09025.55
5.5.270.0170.10325.56
5.5.260.0130.07325.50
5.5.250.0130.10325.29
5.5.240.0070.06324.84
5.5.230.0100.06324.92
5.5.220.0130.05024.95
5.5.210.0230.09324.90
5.5.200.0100.10724.73
5.5.190.0130.07024.78
5.5.180.0100.11024.64
5.5.160.0100.10324.86
5.5.150.0030.07024.89
5.5.140.0200.07724.90
5.5.130.0130.08024.93
5.5.120.0070.09724.87
5.5.110.0070.07724.90
5.5.100.0130.09724.73
5.5.90.0030.07724.75
5.5.80.0200.06724.75
5.5.70.0100.10724.79
5.5.60.0070.07024.71
5.5.50.0070.08324.70
5.5.40.0100.05324.71
5.5.30.0200.05324.70
5.5.20.0130.07724.71
5.5.10.0170.09024.72
5.5.00.0070.06024.62
5.4.450.0030.06023.94
5.4.440.0070.08724.08
5.4.430.0070.10724.00
5.4.420.0100.10023.85
5.4.410.0130.09723.91
5.4.400.0030.09723.70
5.4.390.0130.10023.68
5.4.380.0130.05323.61
5.4.370.0200.09023.59
5.4.360.0200.07323.60
5.4.350.0200.05023.80
5.4.340.0000.07323.52
5.4.320.0130.06023.59
5.4.310.0030.06023.58
5.4.300.0130.08723.57
5.4.290.0100.05723.61
5.4.280.0130.10023.62
5.4.270.0030.07723.79
5.4.260.0030.08723.68
5.4.250.0070.08023.52
5.4.240.0070.11323.76
5.4.230.0030.07023.79
5.4.220.0100.07723.60
5.4.210.0100.07323.61
5.4.200.0170.08023.66
5.4.190.0100.05323.79
5.4.180.0200.09023.76
5.4.170.0130.10723.61
5.4.160.0370.06723.51
5.4.150.0070.08723.55
5.4.140.0130.07320.84
5.4.130.0130.08720.88
5.4.120.0030.08321.13
5.4.110.0170.08021.14
5.4.100.0030.10721.00
5.4.90.0070.11320.90
5.4.80.0030.10021.05
5.4.70.0100.10020.93
5.4.60.0170.05020.91
5.4.50.0100.08021.02
5.4.40.0030.07321.04
5.4.30.0000.05721.14
5.4.20.0200.08720.93
5.4.10.0130.08320.97
5.4.00.0100.05720.49
5.3.290.0100.09018.91
5.3.280.0070.09318.79
5.3.270.0170.09018.79
5.3.260.0100.10318.82
5.3.250.0030.11018.86
5.3.240.0100.06018.82
5.3.230.0030.05718.96
5.3.220.0070.08018.87
5.3.210.0100.10018.92
5.3.200.0130.08018.80
5.3.190.0100.10018.77
5.3.180.0130.06018.92
5.3.170.0100.09718.92
5.3.160.0100.09718.87
5.3.150.0070.09718.92
5.3.140.0030.09318.79
5.3.130.0130.07018.80
5.3.120.0130.10018.88
5.3.110.0100.07318.90
5.3.100.0070.06018.24
5.3.90.0070.05718.27
5.3.80.0130.05718.29
5.3.70.0030.07318.18
5.3.60.0100.07718.13
5.3.50.0100.09318.21
5.3.40.0100.09018.11
5.3.30.0070.09018.15
5.3.20.0100.08718.08
5.3.10.0030.05717.87
5.3.00.0100.08317.88

preferences:
37.09 ms | 401 KiB | 5 Q