3v4l.org

run code in 300+ PHP versions simultaneously
<?php function replace2($matches, $replacements, $frame) { if (!isset($matches[0]) || !is_array($matches[0]) || empty($matches[0])) { return []; } $result = []; foreach ($matches[0] as $value) { if (isset($replacements[$value])) { foreach ($replacements[$value] as $v) { $tmp = str_replace($value, $v, $frame); $result[$tmp] = null; array_shift($matches); replace2($matches, $replacements, $frame); } } } return $result; } function doStuff($frame) { $replacements = [ '{childName}' => [], '{favoriteFood}' => ['pizza', 'soup', 'burger'], '{favoriteToy}' => ['doll', 'teddy bear', 'truck', 'computer'] ]; preg_match_all('/'.implode('|', array_keys($replacements)).'/', $frame, $matches); if (count($matches[0]) < 1) { return [$frame => null]; } return replace2($matches, $replacements, $frame); } $frames = [ '{childName} loves to eat {favoriteFood} and play with his or her {favoriteToy}', '{childName} loves to eat {favoriteFood}', '{childName} loves to play' ]; foreach ($frames as $frame) { var_dump(doStuff($frame)); echo "\n"; }

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)
8.3.60.0150.00018.52
8.3.50.0120.00318.14
8.3.40.0090.00919.09
8.3.30.0120.00318.82
8.3.20.0030.00520.29
8.3.10.0040.00420.73
8.3.00.0040.00421.74
8.2.180.0070.00716.63
8.2.170.0090.00622.96
8.2.160.0090.00622.21
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0080.00021.24
8.2.120.0040.00426.35
8.2.110.0060.00321.30
8.2.100.0120.00017.96
8.2.90.0050.00517.75
8.2.80.0030.00618.98
8.2.70.0000.00817.88
8.2.60.0030.00517.75
8.2.50.0040.00417.75
8.2.40.0000.00818.16
8.2.30.0000.00720.61
8.2.20.0000.00718.00
8.2.10.0050.00318.00
8.2.00.0040.00418.24
8.1.280.0040.01125.92
8.1.270.0060.00922.16
8.1.260.0040.00428.09
8.1.250.0000.00728.09
8.1.240.0030.00619.46
8.1.230.0120.00019.15
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0040.00417.73
8.1.190.0040.00417.60
8.1.180.0030.00518.10
8.1.170.0040.00417.62
8.1.160.0000.00822.26
8.1.150.0080.00018.79
8.1.140.0090.00019.57
8.1.130.0040.00417.76
8.1.120.0060.00617.61
8.1.110.0050.00317.63
8.1.100.0040.00417.66
8.1.90.0000.00817.68
8.1.80.0040.00417.72
8.1.70.0000.00717.55
8.1.60.0000.00817.66
8.1.50.0030.00617.66
8.1.40.0040.00417.61
8.1.30.0040.00817.75
8.1.20.0080.00017.58
8.1.10.0030.00617.79
8.1.00.0040.00417.73
8.0.300.0040.00418.77
8.0.290.0030.00617.00
8.0.280.0000.00818.41
8.0.270.0000.00817.31
8.0.260.0070.00017.30
8.0.250.0060.00317.16
8.0.240.0000.00917.14
8.0.230.0000.00717.14
8.0.220.0070.00016.94
8.0.210.0040.00416.96
8.0.200.0070.00317.10
8.0.190.0020.00517.01
8.0.180.0050.00217.13
8.0.170.0030.00516.95
8.0.160.0040.00416.98
8.0.150.0040.00417.06
8.0.140.0070.00016.96
8.0.130.0030.00313.55
8.0.120.0040.00416.96
8.0.110.0000.00817.09
8.0.100.0050.00317.07
8.0.90.0080.00017.04
8.0.80.0080.00817.03
8.0.70.0000.00817.04
8.0.60.0050.00316.95
8.0.50.0080.00016.96
8.0.30.0110.00417.11
8.0.20.0150.00517.40
8.0.10.0050.00317.20
8.0.00.0120.00717.05
7.4.330.0020.00216.78
7.4.320.0030.00316.83
7.4.300.0060.00016.85
7.4.290.0070.00016.61
7.4.280.0000.00716.80
7.4.270.0030.00616.86
7.4.260.0030.00516.78
7.4.250.0000.00716.75
7.4.240.0020.00516.79
7.4.230.0070.00016.66
7.4.220.0070.01116.92
7.4.210.0070.00816.85
7.4.200.0000.00716.65
7.4.160.0100.00716.75
7.4.150.0090.00917.40
7.4.140.0090.01117.86
7.4.130.0130.00816.75
7.4.120.0070.01116.88
7.4.110.0040.01416.79
7.4.100.0120.00616.69
7.4.90.0060.01216.63
7.4.80.0100.01419.39
7.4.70.0130.00316.52
7.4.60.0090.00916.69
7.4.50.0070.00316.77
7.4.40.0070.01016.63
7.4.30.0100.00916.89
7.4.00.0070.00815.34
7.3.330.0000.00613.51
7.3.320.0030.00313.53
7.3.310.0040.00416.53
7.3.300.0040.00416.46
7.3.290.0040.00416.59
7.3.280.0110.00816.50
7.3.270.0140.00717.40
7.3.260.0140.00416.64
7.3.250.0140.00616.71
7.3.240.0150.00616.81
7.3.230.0140.00616.60
7.3.210.0060.01516.91
7.3.200.0140.00316.52
7.3.190.0080.00816.60
7.3.180.0090.00916.55
7.3.170.0110.01116.72
7.3.160.0100.00616.79
7.3.120.0180.00014.70
7.3.110.0100.01015.10
7.3.100.0100.01015.05
7.3.90.0060.00615.08
7.3.80.0150.00015.06
7.3.70.0060.01014.99
7.3.60.0120.00015.13
7.3.50.0040.01114.93
7.3.40.0090.00615.07
7.3.30.0030.01115.04
7.3.20.0040.01117.03
7.3.10.0060.00616.69
7.3.00.0040.01116.63
7.2.330.0120.01116.89
7.2.320.0140.00316.77
7.2.310.0160.00616.80
7.2.300.0100.00616.88
7.2.290.0110.00616.82
7.2.250.0080.01215.36
7.2.240.0090.00915.13
7.2.230.0120.00615.35
7.2.220.0060.01015.45
7.2.210.0030.00915.25
7.2.200.0060.00615.32
7.2.190.0050.00515.30
7.2.180.0030.00615.02
7.2.170.0000.01115.22
7.2.160.0040.01115.30
7.2.150.0040.00717.11
7.2.140.0130.00317.18
7.2.130.0050.00517.24
7.2.120.0080.00816.91
7.2.110.0100.00016.92
7.2.100.0040.01416.99
7.2.90.0110.00317.13
7.2.80.0030.00717.30
7.2.70.0040.01117.15
7.2.60.0090.00516.97
7.2.50.0000.01116.87
7.2.40.0060.00617.28
7.2.30.0100.00717.16
7.2.20.0030.00616.83
7.2.10.0060.00616.86
7.2.00.0050.01218.37
7.1.330.0060.01115.84
7.1.320.0030.01416.05
7.1.310.0030.01015.70
7.1.300.0060.01116.09
7.1.290.0120.00315.84
7.1.280.0120.00615.75
7.1.270.0030.01016.11
7.1.260.0070.00716.18
7.1.250.0110.00716.02
7.1.240.0050.00615.99
7.1.230.0060.01016.04
7.1.220.0070.01015.89
7.1.210.0040.00816.09
7.1.200.0030.01315.99
7.1.190.0150.00415.98
7.1.180.0000.01215.85
7.1.170.0080.00815.96
7.1.160.0000.01415.68
7.1.150.0100.00316.00
7.1.140.0000.01216.09
7.1.130.0090.00615.91
7.1.120.0080.00815.66
7.1.110.0090.00316.06
7.1.100.0090.00517.15
7.1.90.0030.00616.09
7.1.80.0070.01016.05
7.1.70.0080.00316.42
7.1.60.0110.00817.52
7.1.50.0100.01016.66
7.1.40.0030.01016.00
7.1.30.0080.00815.68
7.1.20.0070.00715.92
7.1.10.0080.00515.98
7.1.00.0030.04519.23
7.0.330.0070.00715.47
7.0.320.0030.01315.32
7.0.310.0120.00315.41
7.0.300.0030.01315.84
7.0.290.0040.00815.54
7.0.280.0100.00715.27
7.0.270.0030.01115.50
7.0.260.0090.00015.63
7.0.250.0070.00715.75
7.0.240.0030.00615.68
7.0.230.0080.00415.77
7.0.220.0000.01415.45
7.0.210.0130.00315.88
7.0.200.0250.00514.96
7.0.190.0040.01115.46
7.0.180.0000.00915.54
7.0.170.0000.01415.48
7.0.160.0000.01315.78
7.0.150.0030.00915.71
7.0.140.0060.00615.61
7.0.130.0080.00415.48
7.0.120.0040.00815.71
7.0.110.0000.01015.34
7.0.100.0030.01315.52
7.0.90.0060.01215.74
7.0.80.0060.00315.80
7.0.70.0030.01315.46
7.0.60.0050.04018.54
7.0.50.0030.04516.79
7.0.40.0020.02916.97
7.0.30.0100.02416.74
7.0.20.0140.02616.94
7.0.10.0010.02616.87
7.0.00.0050.04216.90
5.6.400.0030.01214.33
5.6.390.0030.01414.43
5.6.380.0100.00714.47
5.6.370.0030.01014.44
5.6.360.0070.00714.59
5.6.350.0040.01114.59
5.6.340.0090.00614.44
5.6.330.0070.01114.77
5.6.320.0030.00614.49
5.6.310.0030.01314.70
5.6.300.0000.01714.65
5.6.290.0060.00614.51
5.6.280.0020.02417.69
5.6.270.0060.00314.58
5.6.260.0060.00814.85
5.6.250.0100.00714.37
5.6.240.0060.00914.64
5.6.230.0050.00514.37
5.6.220.0040.00714.68
5.6.210.0100.04017.67
5.6.200.0050.03116.42
5.6.190.0020.03617.51
5.6.180.0150.04217.65
5.6.170.0200.04317.58
5.6.160.0080.02117.37
5.6.150.0060.04216.34
5.6.140.0070.02716.40
5.6.130.0040.02916.37
5.6.120.0080.04417.67
5.6.110.0130.04217.73
5.6.100.0100.04317.94
5.6.90.0060.04617.70
5.6.80.0060.03617.43
5.6.70.0070.01014.29
5.6.60.0030.01414.30
5.6.50.0120.00314.56
5.6.40.0060.00614.29
5.6.30.0040.00814.39
5.6.20.0040.01114.78
5.6.10.0060.00614.37
5.6.00.0030.01014.56
5.5.380.0040.01414.49
5.5.370.0030.01314.45
5.5.360.0040.00714.27
5.5.350.0150.03017.43
5.5.340.0080.02516.25
5.5.330.0090.02917.46
5.5.320.0180.03817.25
5.5.310.0160.02517.33
5.5.300.0030.04016.32
5.5.290.0080.02216.20
5.5.280.0050.04817.65
5.5.270.0050.04217.53
5.5.260.0090.02117.67
5.5.250.0080.04017.57
5.5.240.0110.03617.47
5.5.230.0040.00814.27
5.5.220.0070.00714.21
5.5.210.0100.00314.55
5.5.200.0030.01014.36
5.5.190.0040.01114.63
5.5.180.0060.00914.29
5.5.170.0030.01014.37
5.5.160.0030.00714.46
5.5.150.0040.01114.38
5.5.140.0040.00414.11
5.5.130.0000.01214.37
5.5.120.0060.00614.49
5.5.110.0070.01014.54
5.5.100.0070.01014.49
5.5.90.0130.00314.16
5.5.80.0060.01214.69
5.5.70.0120.00414.29
5.5.60.0080.00414.62
5.5.50.0000.01414.36
5.5.40.0030.00614.51
5.5.30.0060.00614.47
5.5.20.0000.01014.47
5.5.10.0070.01014.54
5.5.00.0030.00614.59

preferences:
63.2 ms | 401 KiB | 5 Q