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+)\}\}"; $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 template2($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.70.0100.01018.55
8.3.60.0090.01316.75
8.3.50.0130.00621.19
8.3.40.0040.01118.88
8.3.30.0120.00418.84
8.3.20.0040.00420.34
8.3.10.0050.00323.70
8.3.00.0070.00023.70
8.2.190.0060.00916.70
8.2.180.0130.00618.58
8.2.170.0090.00618.80
8.2.160.0090.00622.96
8.2.150.0000.00725.66
8.2.140.0050.00324.66
8.2.130.0050.00319.66
8.2.120.0040.00426.35
8.2.110.0000.01020.36
8.2.100.0080.00417.93
8.2.90.0040.00419.22
8.2.80.0040.00418.16
8.2.70.0060.00317.61
8.2.60.0050.00318.04
8.2.50.0030.00618.07
8.2.40.0000.00820.59
8.2.30.0000.00720.63
8.2.20.0000.00717.89
8.2.10.0080.00018.08
8.2.00.0060.00318.11
8.1.280.0190.00325.92
8.1.270.0070.00322.14
8.1.260.0030.00528.09
8.1.250.0040.00428.09
8.1.240.0060.00321.03
8.1.230.0040.00819.03
8.1.220.0030.00517.74
8.1.210.0040.00418.77
8.1.200.0030.00617.13
8.1.190.0000.00817.22
8.1.180.0060.00318.10
8.1.170.0040.00418.50
8.1.160.0030.00520.87
8.1.150.0070.00018.84
8.1.140.0030.00619.53
8.1.130.0040.00417.61
8.1.120.0040.00417.41
8.1.110.0080.00017.46
8.1.100.0000.00817.53
8.1.90.0080.00017.45
8.1.80.0040.00417.50
8.1.70.0000.00717.52
8.1.60.0030.00617.50
8.1.50.0040.00417.60
8.1.40.0030.00617.46
8.1.30.0060.00317.59
8.1.20.0040.00417.59
8.1.10.0080.00017.72
8.1.00.0040.00417.41
8.0.300.0000.00718.77
8.0.290.0000.00816.75
8.0.280.0030.00318.50
8.0.270.0070.00017.21
8.0.260.0000.00617.21
8.0.250.0030.00317.11
8.0.240.0000.01016.99
8.0.230.0000.00716.96
8.0.220.0030.00317.02
8.0.210.0030.00316.95
8.0.200.0040.00416.96
8.0.190.0040.00417.03
8.0.180.0000.00816.97
8.0.170.0000.00817.02
8.0.160.0000.00816.96
8.0.150.0000.00716.96
8.0.140.0040.00416.78
8.0.130.0040.00413.41
8.0.120.0030.00616.93
8.0.110.0020.00516.90
8.0.100.0000.00716.98
8.0.90.0000.00716.82
8.0.80.0100.00717.03
8.0.70.0000.00716.78
8.0.60.0040.00417.00
8.0.50.0000.00716.77
8.0.30.0110.00817.25
8.0.20.0130.00617.40
8.0.10.0070.00017.05
8.0.00.0100.01017.00
7.4.330.0060.00016.67
7.4.320.0060.00016.69
7.4.300.0000.00616.46
7.4.290.0000.00716.64
7.4.280.0060.00616.64
7.4.270.0000.00716.59
7.4.260.0070.00016.58
7.4.250.0080.00016.59
7.4.240.0060.00216.62
7.4.230.0040.00416.46
7.4.220.0150.01316.49
7.4.210.0100.00616.65
7.4.200.0000.00716.34
7.4.160.0130.00716.56
7.4.150.0000.01817.40
7.4.140.0080.01117.86
7.4.130.0100.01016.60
7.4.120.0120.00716.60
7.4.110.0030.01416.49
7.4.100.0110.00616.63
7.4.90.0070.01016.58
7.4.80.0040.01419.39
7.4.70.0080.01216.73
7.4.60.0120.00616.57
7.4.50.0080.00816.49
7.4.40.0120.00416.75
7.4.30.0060.00916.61
7.4.00.0060.01015.00
7.3.330.0000.00613.47
7.3.320.0040.00413.39
7.3.310.0030.00516.57
7.3.300.0050.00216.43
7.3.290.0060.00016.41
7.3.280.0070.00916.39
7.3.270.0120.00617.40
7.3.260.0030.01416.77
7.3.250.0080.00916.44
7.3.240.0110.00616.48
7.3.230.0090.01216.39
7.3.210.0070.01016.32
7.3.200.0090.00919.39
7.3.190.0110.00616.40
7.3.180.0100.00716.71
7.3.170.0070.01416.33
7.3.160.0090.00616.47
7.2.330.0110.00816.61
7.2.320.0030.01316.79
7.2.310.0100.01016.55
7.2.300.0030.01416.79
7.2.290.0080.01616.48
7.2.00.0000.01219.24
7.1.100.0000.01218.24
7.1.70.0040.00417.13
7.1.60.0000.01819.20
7.1.50.0110.01416.84
7.1.00.0000.07722.45
7.0.200.0030.00516.82
7.0.60.0030.08021.84
7.0.50.0100.05717.84
7.0.40.0130.07020.05
7.0.30.0300.07720.24
7.0.20.0370.07720.05
7.0.10.0100.04320.30
7.0.00.0000.05020.10
5.6.280.0000.03721.11
5.6.210.0070.07320.48
5.6.200.0130.03318.28
5.6.190.0030.04720.50
5.6.180.0530.06720.49
5.6.170.0270.08020.48
5.6.160.0030.04320.51
5.6.150.0000.04718.19
5.6.140.0070.04318.13
5.6.130.0100.06018.18
5.6.120.0070.06021.06
5.6.110.0130.05721.06
5.6.100.0100.05021.05
5.6.90.0070.08721.05
5.6.80.0130.07320.41
5.5.350.0300.06720.40
5.5.340.0100.06718.07
5.5.330.0100.08020.40
5.5.320.0170.06320.35
5.5.310.0400.06720.23
5.5.300.0070.08717.98
5.5.290.0100.03317.95
5.5.280.0230.07020.89
5.5.270.0070.06320.69
5.5.260.0100.07720.66
5.5.250.0100.06320.79
5.5.240.0200.03720.16

preferences:
59.53 ms | 401 KiB | 5 Q