3v4l.org

run code in 300+ PHP versions simultaneously
<?php function template($template, $vals) { $matches = array(); $regex = "/\{\{(\S+)\}\}/e"; $rendered = $template; // in case no matches are found preg_match_all($regex, $template, $matches, PREG_OFFSET_CAPTURE, 3); foreach ($matches[0] as $found) { $block = $found[0]; $offset = $found[0]; $k = str_replace('{{', '', $block); $k = str_replace('}-}', '', $k); $rendered = preg_replace($regex, '$vals[\\1]', $template); } return $rendered; } function template2($template, $vals) { $matches = array(); $regex = "/\{\{(\S+)\}\}/e"; $rendered = $template; // in case no matches are found preg_match_all($regex, $template, $matches, PREG_OFFSET_CAPTURE, 3); foreach ($matches[0] as $found) { $block = $found[0]; $offset = $found[0]; $k = str_replace('{{', '', $block); $k = str_replace('}-}', '', $k); $rendered = preg_replace_callback($regex, function($matches) { return $matches[0]; }, $template); } return $rendered; } $template = "test {{ME}}."; $vals = array('ME' => 'beep'); echo template($template, $vals);

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.0160.00616.88
8.3.50.0150.00521.07
8.3.40.0070.00718.98
8.3.30.0070.00718.70
8.3.20.0080.00020.33
8.3.10.0040.00423.53
8.3.00.0080.00023.70
8.2.180.0120.00918.54
8.2.170.0120.00319.02
8.2.160.0120.00322.96
8.2.150.0050.00325.66
8.2.140.0050.00324.66
8.2.130.0050.00319.76
8.2.120.0040.00426.35
8.2.110.0040.00422.22
8.2.100.0030.00918.05
8.2.90.0030.00519.22
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0040.00418.04
8.2.50.0000.00818.07
8.2.40.0080.00020.65
8.2.30.0040.00420.71
8.2.20.0000.00817.70
8.2.10.0000.00718.21
8.2.00.0050.00418.16
8.1.280.0040.01125.92
8.1.270.0030.00621.98
8.1.260.0040.00428.09
8.1.250.0070.00028.09
8.1.240.0000.00823.97
8.1.230.0070.00419.16
8.1.220.0030.00517.74
8.1.210.0040.00418.77
8.1.200.0000.00817.35
8.1.190.0080.00017.22
8.1.180.0030.00518.10
8.1.170.0040.00418.53
8.1.160.0030.00620.80
8.1.150.0000.00718.93
8.1.140.0080.00019.57
8.1.130.0070.00017.70
8.1.120.0050.00217.46
8.1.110.0050.00317.49
8.1.100.0040.00417.39
8.1.90.0000.00717.54
8.1.80.0080.00017.51
8.1.70.0060.00317.38
8.1.60.0060.00317.68
8.1.50.0030.00617.46
8.1.40.0000.01017.54
8.1.30.0080.00017.61
8.1.20.0020.00517.73
8.1.10.0000.00817.64
8.1.00.0040.00417.48
8.0.300.0040.00418.77
8.0.290.0080.00016.88
8.0.280.0040.00418.39
8.0.270.0070.00017.29
8.0.260.0000.00617.37
8.0.250.0030.00316.94
8.0.240.0030.00617.08
8.0.230.0030.00317.04
8.0.220.0030.00316.97
8.0.210.0070.00016.98
8.0.200.0030.00317.07
8.0.190.0050.00316.93
8.0.180.0040.00417.00
8.0.170.0040.00417.04
8.0.160.0000.00816.96
8.0.150.0000.00716.84
8.0.140.0050.00316.99
8.0.130.0060.00013.46
8.0.120.0040.00416.96
8.0.110.0070.00016.89
8.0.100.0040.00417.00
8.0.90.0040.00417.02
8.0.80.0070.01417.02
8.0.70.0000.00817.04
8.0.60.0050.00216.87
8.0.50.0050.00316.86
8.0.30.0100.00617.05
8.0.20.0110.00817.40
8.0.10.0040.00416.98
8.0.00.0100.00816.91
7.4.330.0030.00316.77
7.4.320.0000.00616.66
7.4.300.0040.00416.56
7.4.290.0000.00716.54
7.4.280.0040.01116.56
7.4.270.0030.00316.67
7.4.260.0030.00516.68
7.4.250.0000.00716.52
7.4.240.0080.00016.59
7.4.230.0000.00816.73
7.4.220.0060.01216.67
7.4.210.0040.01516.61
7.4.200.0070.00016.71
7.4.160.0090.00616.69
7.4.150.0220.04217.40
7.4.140.0090.00917.86
7.4.130.0090.01216.65
7.4.120.0130.00716.64
7.4.110.0030.01416.71
7.4.100.0130.01016.64
7.4.90.0130.01016.61
7.4.80.0110.00719.39
7.4.70.0070.01116.47
7.4.60.0140.00616.52
7.4.50.0030.01416.66
7.4.40.0110.00616.55
7.4.30.0120.00416.69
7.4.00.0060.00914.98
7.3.330.0030.00313.41
7.3.320.0040.00413.41
7.3.310.0050.00216.29
7.3.300.0000.00716.28
7.3.290.0030.00316.36
7.3.280.0050.01416.35
7.3.270.0180.00017.40
7.3.260.0000.01716.61
7.3.250.0130.00416.39
7.3.240.0080.01116.61
7.3.230.0160.00416.40
7.3.210.0140.00316.43
7.3.200.0070.01019.39
7.3.190.0080.00816.71
7.3.180.0100.00616.22
7.3.170.0130.00716.27
7.3.160.0140.00316.64
7.3.10.0040.00416.79
7.3.00.0000.00816.64
7.2.330.0090.00916.88
7.2.320.0100.01316.63
7.2.310.0100.01416.86
7.2.300.0090.01316.84
7.2.290.0040.01216.81
7.2.130.0060.00617.04
7.2.120.0080.00817.14
7.2.110.0080.00817.08
7.2.100.0100.00317.16
7.2.90.0100.00316.99
7.2.80.0070.00816.99
7.2.70.0130.00317.33
7.2.60.0100.00517.10
7.2.50.0070.00717.08
7.2.40.0030.00917.13
7.2.30.0090.00317.28
7.2.20.0060.00917.10
7.2.10.0070.00717.29
7.2.00.0060.00618.38
7.1.250.0030.01015.81
7.1.200.0100.00015.81
7.1.100.0040.00818.06
7.1.70.0060.00617.55
7.1.60.0070.01419.20
7.1.50.0000.02317.03
7.1.00.0000.08022.42
7.0.200.0000.00916.70
7.0.60.0100.06021.60
7.0.50.0030.04318.00
7.0.40.0030.04320.07
7.0.30.0300.07020.08
7.0.20.0330.07020.26
7.0.10.0100.04320.35
7.0.00.0070.06320.27
5.6.280.0000.03720.79
5.6.210.0070.06320.68
5.6.200.0130.06718.19
5.6.190.0000.04720.64
5.6.180.0370.06320.61
5.6.170.0200.06320.47
5.6.160.0000.07320.54
5.6.150.0100.03718.15
5.6.140.0070.04018.17
5.6.130.0030.04318.15
5.6.120.0130.04721.02
5.6.110.0100.07021.03
5.6.100.0070.06320.97
5.6.90.0070.05320.99
5.6.80.0130.08020.44
5.5.350.0300.05020.30
5.5.340.0030.04717.95
5.5.330.0100.07020.25
5.5.320.0130.04720.35
5.5.310.0330.07020.27
5.5.300.0030.07717.95
5.5.290.0200.06717.99
5.5.280.0100.07020.86
5.5.270.0070.04020.89
5.5.260.0100.08020.80
5.5.250.0030.06320.79
5.5.240.0170.07320.30

preferences:
51.73 ms | 401 KiB | 5 Q