3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Template { public $dir = ''; private $extension = 'php'; private $template = ''; private $parse; function __construct($dir = false, $extension = 'php') { if ($dir) { $this->dir = preg_replace('#/+$#', '', $dir); } else { $this->dir = $dir; } $this->extension = $extension; } public function load() { if (func_num_args() > 0) { $files = func_get_args(); foreach ($files as $file) { if (is_file($this->dir . '/' . $file . '.' . $this->extension)) { $this->template .= file_get_contents($this->dir . '/' . $file . '.' . $this->extension); } else { trigger_error('Шаблона ' . htmlspecialchars($file . '.' . $this->extension) . ' не существует.', E_USER_WARNING); } } } } public function clear() { $this->template = ''; return true; } private function parseInclude($template) { //Парсим блоки {include=file} $count = preg_match_all('/{include=([\w\/]+)}/i', $template, $match); if ($count > 0) { $count -= 1; for ($i = 0; $i <= $count; $i++) { $file = $this->dir . '/' . $match[1][$i] . '.' . $this->extension; if (is_file($file)) { $template = str_replace($match[0][$i], $this->parseInclude(file_get_contents($file)), $template); } else { $template = str_replace($match[0][$i], '', $template); trigger_error('Ошибка вставки шаблона <b>' . htmlspecialchars($match[1][$i]) . '</b>. Шаблона <b>' . htmlspecialchars($file) . '</b> не существует.', E_USER_WARNING); } } } return $template; } private function parseBlock($parse, $template) { $c = preg_match_all('#\[([\w\-\!]+)\](.*?)\[/\1\]#is', $template, $match); if ($c > 0) { $c -= 1; for ($i = 0; $i <= $c; $i++) { if ($match[1][$i]{0} == '!') { if (isset($parse[substr($match[1][$i], 1)])) $match[2][$i] = ''; } else { if (!isset($parse[$match[1][$i]])) $match[2][$i] = ''; } $template = str_replace($match[0][$i], $match[2][$i], $template); } $template = $this->parseBlock($parse, $template); } return $template; } public function parse($parse) { if (empty($this->template)) { trigger_error('Шаблон не задан или он пустой.', E_USER_WARNING); } else { $this->parse = $parse; $template = $this->parseInclude($this->template); $template = $this->parseBlock($parse, $template); return preg_replace('#\{([a-z0-9\-_]*?)\}#Ssie', '( ( isset($parse[\'\1\']) ) ? $parse[\'\1\'] : \'\' );', $template); } } } ?>

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.0140.00018.30
8.3.50.0120.00621.02
8.3.40.0000.01518.71
8.3.30.0040.01918.72
8.3.20.0000.00818.54
8.3.10.0080.00020.80
8.3.00.0040.00423.65
8.2.180.0110.00418.29
8.2.170.0000.02022.96
8.2.160.0130.00020.35
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0040.00421.10
8.2.110.0080.00320.29
8.2.100.0080.00317.66
8.2.90.0040.00419.05
8.2.80.0000.00817.97
8.2.70.0060.00617.50
8.2.60.0000.00817.79
8.2.50.0080.00018.07
8.2.40.0040.00418.09
8.2.30.0030.00519.63
8.2.20.0030.00517.64
8.2.10.0070.00017.76
8.2.00.0000.00817.66
8.1.280.0040.01125.92
8.1.270.0040.00423.99
8.1.260.0100.00726.35
8.1.250.0080.00028.09
8.1.240.0030.00622.30
8.1.230.0060.00621.09
8.1.220.0040.00418.77
8.1.210.0000.00819.10
8.1.200.0100.00017.13
8.1.190.0000.00817.53
8.1.180.0040.00418.10
8.1.170.0050.00318.77
8.1.160.0040.00418.69
8.1.150.0040.00418.55
8.1.140.0000.00917.27
8.1.130.0000.00717.75
8.1.120.0030.00517.30
8.1.110.0000.00817.36
8.1.100.0050.00217.43
8.1.90.0050.00217.28
8.1.80.0050.00317.33
8.1.70.0030.00317.36
8.1.60.0080.00317.45
8.1.50.0000.00817.39
8.1.40.0040.00417.43
8.1.30.0050.00317.52
8.1.20.0030.00517.50
8.1.10.0030.00617.45
8.1.00.0030.00717.23
8.0.300.0000.00819.98
8.0.290.0080.00017.18
8.0.280.0000.00718.39
8.0.270.0070.00017.13
8.0.260.0000.00716.73
8.0.250.0000.00716.96
8.0.240.0000.00816.94
8.0.230.0040.00416.85
8.0.220.0000.00716.77
8.0.210.0000.00816.91
8.0.200.0070.00016.86
8.0.190.0080.00016.96
8.0.180.0050.00216.76
8.0.170.0040.00416.95
8.0.160.0000.00716.93
8.0.150.0040.00416.88
8.0.140.0050.00316.75
8.0.130.0040.00413.25
8.0.120.0030.00616.78
8.0.110.0050.00316.75
8.0.100.0050.00316.84
8.0.90.0040.00417.01
8.0.80.0130.00316.92
8.0.70.0020.00516.93
8.0.60.0040.00416.88
8.0.50.0070.00016.68
8.0.30.0070.01217.02
8.0.20.0080.01217.40
8.0.10.0040.00416.90
8.0.00.0070.01116.73
7.4.330.0050.00014.70
7.4.320.0060.00016.37
7.4.300.0040.00416.54
7.4.290.0000.01116.54
7.4.280.0000.00716.46
7.4.270.0030.00316.45
7.4.260.0040.00313.16
7.4.250.0080.00016.42
7.4.240.0070.00016.52
7.4.230.0030.00316.47
7.4.220.0100.00716.54
7.4.210.0060.00916.48
7.4.200.0040.00416.57
7.4.190.0000.00716.48
7.4.160.0060.00916.67
7.4.150.0060.01317.40
7.4.140.0080.01117.86
7.4.130.0120.00816.49
7.4.120.0100.00816.52
7.4.110.0070.01016.46
7.4.100.0060.01016.50
7.4.90.0100.00716.45
7.4.80.0060.01219.37
7.4.70.0130.00316.63
7.4.60.0130.00416.30
7.4.50.0040.00416.65
7.4.40.0040.01122.27
7.4.30.0100.00716.51
7.4.00.0070.01014.77
7.3.330.0020.00213.27
7.3.320.0030.00313.27
7.3.310.0030.00316.20
7.3.300.0000.00716.12
7.3.290.0070.00716.22
7.3.280.0090.01016.21
7.3.270.0040.01317.40
7.3.260.0090.00918.24
7.3.250.0060.01116.24
7.3.240.0100.00616.18
7.3.230.0120.00416.49
7.3.210.0160.00616.46
7.3.200.0140.00719.39
7.3.190.0130.00616.46
7.3.180.0090.00616.27
7.3.170.0090.00616.35
7.3.160.0090.00616.52
7.3.120.0100.00714.63
7.2.330.0110.00616.39
7.2.320.0120.00616.58
7.2.310.0160.00716.50
7.2.300.0130.00316.31
7.2.290.0030.01316.34
7.2.60.0090.00616.76
7.1.200.0070.00715.28
7.1.70.0000.01017.01
7.1.60.0140.01119.40
7.1.50.0140.01016.52
7.1.00.0100.05322.35
7.0.200.0110.00314.92
7.0.140.0030.07322.18
7.0.70.0130.07021.78
7.0.60.0070.07721.73
7.0.50.0070.08322.16
7.0.40.0030.09020.04
7.0.30.0030.06720.08
7.0.20.0070.05320.10
7.0.10.0070.07720.13
7.0.00.0030.08720.04
5.6.280.0100.06720.91
5.6.220.0070.08020.64
5.6.210.0000.08720.58
5.6.200.0070.05320.98
5.6.190.0030.07021.19
5.6.180.0070.08321.11
5.6.170.0070.08020.97
5.6.160.0030.05021.06
5.6.150.0030.08321.13
5.6.140.0100.05021.06
5.6.130.0000.09021.04
5.6.120.0000.04721.20
5.6.110.0000.07320.97
5.6.100.0030.07721.17
5.6.90.0030.04720.91
5.6.80.0100.05320.42
5.6.70.0100.07320.43
5.6.60.0070.08020.43
5.6.50.0030.04320.51
5.6.40.0030.05320.51
5.6.30.0030.06020.41
5.6.20.0030.06320.43
5.6.10.0070.05020.45
5.6.00.0070.05720.50
5.5.360.0030.09020.38
5.5.350.0070.08020.43
5.5.340.0000.08020.86
5.5.330.0030.08720.66
5.5.320.0070.08020.91
5.5.310.0070.07320.94
5.5.300.0070.08720.90
5.5.290.0000.06020.91
5.5.280.0030.08320.79
5.5.270.0030.08720.84
5.5.260.0030.05020.90
5.5.250.0030.07320.66
5.5.240.0100.07720.17
5.5.230.0070.08020.14
5.5.220.0100.04320.27
5.5.210.0100.07320.32
5.5.200.0030.08320.26
5.5.190.0100.07720.25
5.5.180.0030.08320.16
5.5.160.0000.04720.16
5.5.150.0070.05720.01
5.5.140.0100.06720.19
5.5.130.0000.07720.10
5.5.120.0070.07720.27
5.5.110.0070.05020.25
5.5.100.0100.06720.00
5.5.90.0030.07720.14
5.5.80.0030.08020.09
5.5.70.0070.07720.08
5.5.60.0070.07320.17
5.5.50.0100.06720.18
5.5.40.0030.04020.16
5.5.30.0130.06320.16
5.5.20.0100.07720.10
5.5.10.0130.05019.98
5.5.00.0030.04719.95
5.4.450.0000.08019.42
5.4.440.0000.04319.27
5.4.430.0030.04019.36
5.4.420.0070.07319.41
5.4.410.0000.06719.04
5.4.400.0100.06719.03
5.4.390.0070.07319.02
5.4.380.0070.05719.23
5.4.370.0030.08019.13
5.4.360.0030.04718.87
5.4.350.0000.07318.88
5.4.340.0070.07719.12
5.4.320.0000.07719.12
5.4.310.0100.06719.09
5.4.300.0030.08019.16
5.4.290.0100.05319.02
5.4.280.0100.07019.12
5.4.270.0070.07018.87
5.4.260.0030.07719.04
5.4.250.0000.05019.04
5.4.240.0070.07318.84
5.4.230.0070.07019.22
5.4.220.0000.05318.86
5.4.210.0030.03719.17
5.4.200.0070.07319.15
5.4.190.0000.07719.22
5.4.180.0030.04019.03
5.4.170.0030.07319.08
5.4.160.0030.07719.21
5.4.150.0030.05719.01
5.4.140.0070.04316.20
5.4.130.0000.07316.45
5.4.120.0030.07716.44
5.4.110.0030.03316.33
5.4.100.0030.07316.36
5.4.90.0000.03316.47
5.4.80.0030.07316.43
5.4.70.0030.07716.27
5.4.60.0000.08016.40
5.4.50.0070.04716.37
5.4.40.0030.05016.43
5.4.30.0030.05016.48
5.4.20.0030.07016.35
5.4.10.0030.06016.42
5.4.00.0070.07015.86
5.3.290.0030.07714.61
5.3.280.0030.06714.76
5.3.270.0000.07714.69
5.3.260.0000.03314.72
5.3.250.0030.06714.75
5.3.240.0030.06314.59
5.3.230.0000.06014.68
5.3.220.0000.06014.52
5.3.210.0000.04714.71
5.3.200.0030.07714.73
5.3.190.0030.07014.57
5.3.180.0030.06714.68
5.3.170.0070.06014.64
5.3.160.0070.07714.64
5.3.150.0030.07714.65
5.3.140.0070.06714.51
5.3.130.0030.04314.52
5.3.120.0030.07314.63
5.3.110.0000.07714.63
5.3.100.0030.06314.03
5.3.90.0030.07314.05
5.3.80.0000.06714.09
5.3.70.0000.08313.93
5.3.60.0100.05714.09
5.3.50.0100.05314.07
5.3.40.0070.06314.06
5.3.30.0030.06313.82
5.3.20.0030.07013.85
5.3.10.0030.04713.59
5.3.00.0000.07313.69
5.2.170.0000.06011.17
5.2.160.0030.05711.24
5.2.150.0000.05311.29
5.2.140.0100.05311.10
5.2.130.0070.03711.23
5.2.120.0000.06311.25
5.2.110.0030.04011.15
5.2.100.0000.06311.24
5.2.90.0070.05711.23
5.2.80.0030.05711.20
5.2.70.0030.06011.03
5.2.60.0000.06311.00
5.2.50.0030.06311.13
5.2.40.0030.06011.06
5.2.30.0030.06311.08
5.2.20.0030.06011.11
5.2.10.0000.05710.96
5.2.00.0070.06010.69
5.1.60.0030.04010.62
5.1.50.0070.04310.62
5.1.40.0070.05010.62
5.1.30.0000.06010.62
5.1.20.0000.05010.62
5.1.10.0030.05310.62
5.1.00.0070.05010.62
5.0.50.0000.04710.62
5.0.40.0000.03710.62
5.0.30.0030.05710.62
5.0.20.0000.03310.62
5.0.10.0000.02010.62
5.0.00.0000.05010.62
4.4.90.0000.03010.62
4.4.80.0030.02710.62
4.4.70.0100.02710.62
4.4.60.0070.03310.62
4.4.50.0030.02310.62
4.4.40.0000.03710.62
4.4.30.0000.03310.62
4.4.20.0000.02710.62
4.4.10.0030.02710.62
4.4.00.0070.03310.62
4.3.110.0030.02710.62
4.3.100.0000.03710.62
4.3.90.0030.02310.62
4.3.80.0070.04010.62
4.3.70.0000.03310.62
4.3.60.0030.03010.62
4.3.50.0030.02310.62
4.3.40.0000.05010.62
4.3.30.0000.03310.62
4.3.20.0070.03310.62
4.3.10.0000.01710.62
4.3.00.0030.02710.62

preferences:
61.2 ms | 400 KiB | 5 Q