3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Template { private $_template = ''; private $_assigns = array(); private $_prepared_code = null; const VALID_VARIABLE = '[a-zA-Z0-9_\x7f-\xff]*'; const TAG_SIGN_OPEN = '{'; const TAG_SIGN_CLOSE = '}'; public function __construct($template) { $this->_template = $template; } public function assign($name, $value) { $this->_assign($name, $value); } private function _assign($name, $value, array &$assigns = null) { if ($assigns == null) $this->_assigns[$name] = $value; else $assigns[$name] = $value; } public function assignArray($array) { $this->_assignArray($array); } private function _assignArray($array, array &$assigns = null) { foreach ($array as $name => $value) $this->_assign($name, $value, $assigns); } private function _getToken($string, $sign, $pos, &$token) { $position = strpos($string, $sign, $pos); if ($position === false) { $token = substr($string, $pos); $pos = false; } else { $token = substr($string, $pos, $position - $pos); $pos = $position + strlen($sign); } return $pos; } private function _prepareCode() { $prepared_code = '?' . '>'; $pos = 0; while ($pos !== false) { $pos = $this->_getToken($this->_template, self::TAG_SIGN_OPEN, $pos, $token); $prepared_code .= $token; if ($pos !== false) { $pos = $this->_getToken($this->_template, self::TAG_SIGN_CLOSE, $pos, $token); if ($pos === false) throw new Exception('Template syntax error. Expected "}"'); switch (true) { case preg_match('/^' . self::VALID_VARIABLE . '$/', $token): $prepared_code .= '<?php echo $assigns[\'' . $token . '\'] ?' . '>'; break; case preg_match('/^loop +(' . self::VALID_VARIABLE . ')$/', $token, $match): $prepared_code .= '<?php foreach ($assigns[\'' . $match[1] . '\'] as $__index => $__tmp)' . '{$this->_assignArray($__tmp, $assigns); unset($__tmp); ?' . '>'; break; case preg_match('/^end +loop$/', $token): $prepared_code .= '<?php } ?>'; break; case preg_match('/^\%index\%$/', $token): $prepared_code .= '<?php echo $__index ?' . '>'; break; default: throw new Exception('Template syntax error. Unexpected token "' . $token . '"'); break; } } } return $prepared_code; } public function getPreparedCode() { if ($this->_prepared_code === null) $this->_prepared_code = $this->_prepareCode(); return $this->_prepared_code; } private function _execute($prepared_code) { $assigns = $this->_assigns; ob_start(); eval($prepared_code); $content = ob_get_contents(); ob_end_clean(); return $content; } public function parse() { return $this->_execute($this->getPreparedCode()); } } $templateHtml = <<<END_HTML <div>{this}</div> {loop items} <div>{%index%}. {name}</div> {end loop} END_HTML; $template = new Template($templateHtml); $template->assign('this', 'test'); $template->assign('items', array( array('name' => 'First'), array('name' => 'Second') )); echo $template->parse();

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.0090.01218.55
8.3.50.0070.00718.19
8.3.40.0100.00619.04
8.3.30.0170.00019.13
8.3.20.0080.00020.20
8.3.10.0090.00022.03
8.3.00.0060.00322.57
8.2.180.0080.01116.88
8.2.170.0060.01522.96
8.2.160.0060.00920.96
8.2.150.0100.00724.18
8.2.140.0030.00524.66
8.2.130.0110.00726.16
8.2.120.0080.00019.61
8.2.110.0090.00022.39
8.2.100.0090.00318.09
8.2.90.0030.00619.33
8.2.80.0040.00418.05
8.2.70.0000.00817.88
8.2.60.0000.00818.16
8.2.50.0050.00318.07
8.2.40.0000.00918.34
8.2.30.0040.00418.21
8.2.20.0040.00417.92
8.2.10.0040.00418.02
8.2.00.0030.00517.99
8.1.270.0030.00523.86
8.1.260.0120.00326.35
8.1.250.0040.01428.09
8.1.240.0040.00423.84
8.1.230.0060.00619.28
8.1.220.0060.00317.80
8.1.210.0050.00318.77
8.1.200.0070.00317.48
8.1.190.0040.00417.51
8.1.180.0000.00818.10
8.1.170.0040.00418.84
8.1.160.0070.00022.05
8.1.150.0040.00418.85
8.1.140.0030.00617.54
8.1.130.0030.00317.88
8.1.120.0000.00717.71
8.1.110.0070.00017.59
8.1.100.0040.00417.67
8.1.90.0080.00017.70
8.1.80.0070.00017.71
8.1.70.0080.00017.62
8.1.60.0090.00017.83
8.1.50.0030.00617.78
8.1.40.0040.00417.73
8.1.30.0050.00517.85
8.1.20.0030.00617.77
8.1.10.0030.00617.64
8.1.00.0040.00417.65
8.0.300.0070.00018.77
8.0.290.0000.00817.18
8.0.280.0040.00418.41
8.0.270.0000.00717.38
8.0.260.0030.00317.09
8.0.250.0040.00417.14
8.0.240.0000.00717.23
8.0.230.0000.00717.16
8.0.220.0000.00817.18
8.0.210.0030.00317.07
8.0.200.0070.00017.23
8.0.190.0070.00017.30
8.0.180.0000.00717.21
8.0.170.0000.00917.16
8.0.160.0000.00817.23
8.0.150.0050.00217.12
8.0.140.0050.00217.01
8.0.130.0060.00013.55
8.0.120.0040.00417.12
8.0.110.0040.00416.99
8.0.100.0000.00716.96
8.0.90.0000.00717.12
8.0.80.0110.00717.18
8.0.70.0030.00517.07
8.0.60.0000.00816.95
8.0.50.0040.00417.15
8.0.30.0120.00917.28
8.0.20.0120.00617.42
8.0.10.0030.00517.31
8.0.00.0090.00917.14
7.4.330.0000.00615.00
7.4.320.0070.00016.82
7.4.300.0000.00616.71
7.4.290.0070.00016.79
7.4.280.0030.00316.68
7.4.270.0000.00916.79
7.4.260.0050.00316.75
7.4.250.0070.00016.69
7.4.240.0060.00216.80
7.4.230.0040.00416.82
7.4.220.0140.00316.82
7.4.210.0060.01116.75
7.4.200.0080.00016.94
7.4.190.0040.00416.79
7.4.160.0080.00816.65
7.4.150.0100.00717.40
7.4.140.0080.01017.86
7.4.130.0120.00716.83
7.4.120.0080.01016.72
7.4.110.0150.00616.75
7.4.100.0110.00816.59
7.4.90.0070.01016.77
7.4.80.0100.01019.39
7.4.70.0140.00516.73
7.4.60.0090.01216.67
7.4.50.0050.00016.65
7.4.40.0040.01222.77
7.4.30.0070.01016.92
7.4.00.0070.00915.38
7.3.330.0000.00513.63
7.3.320.0030.00313.60
7.3.310.0040.00416.67
7.3.300.0040.00416.50
7.3.290.0090.00916.59
7.3.280.0090.00716.56
7.3.270.0120.00617.40
7.3.260.0150.00916.87
7.3.250.0100.01016.63
7.3.240.0070.01016.62
7.3.230.0070.01016.72
7.3.210.0130.00316.62
7.3.200.0180.00419.39
7.3.190.0110.00916.45
7.3.180.0130.00616.74
7.3.170.0100.01016.75
7.3.160.0130.00316.91
7.3.120.0100.00514.97
7.3.110.0060.01315.24
7.3.100.0120.00314.93
7.3.90.0070.01015.22
7.3.80.0000.00915.23
7.3.70.0000.01414.91
7.3.60.0070.00715.19
7.3.50.0030.01014.88
7.3.40.0070.00715.17
7.3.30.0070.00715.08
7.3.20.0060.01016.79
7.3.10.0100.01016.93
7.3.00.0070.00716.95
7.2.330.0060.01216.88
7.2.320.0110.00816.94
7.2.310.0110.00717.09
7.2.300.0140.00316.94
7.2.290.0100.01017.04
7.2.250.0030.01315.13
7.2.240.0130.00715.29
7.2.230.0060.00915.12
7.2.220.0140.00315.22
7.2.210.0000.00915.31
7.2.200.0060.00615.44
7.2.190.0000.01215.44
7.2.180.0070.01015.46
7.2.170.0060.00915.31
7.1.330.0060.00615.98
7.1.320.0030.00916.04
7.1.310.0070.00715.63
7.1.300.0070.00715.77
7.1.290.0030.00916.04
7.1.280.0100.00315.75
7.1.270.0090.00616.09
7.1.260.0090.00615.75
7.1.70.0040.00417.54
7.1.60.0040.01519.82
7.1.50.0030.01417.21
7.1.00.0000.08022.37
7.0.200.0070.00716.78
7.0.140.0030.07722.14
7.0.100.0130.02720.05
7.0.90.0100.04319.91
7.0.80.0100.03320.14
7.0.70.0200.05019.94
7.0.60.0070.08020.03
7.0.50.0030.07020.32
7.0.40.0070.08319.97
7.0.30.0070.08319.97
7.0.20.0170.06020.05
7.0.10.0100.03720.09
7.0.00.0070.08020.13
5.6.280.0000.07020.96
5.6.250.0030.07320.60
5.6.240.0100.03720.61
5.6.230.0030.04320.48
5.6.220.0130.03320.63
5.6.210.0000.06020.45
5.6.200.0030.09021.12
5.6.190.0000.08020.92
5.6.180.0100.07021.00
5.6.170.0070.08021.02
5.6.160.0130.07021.04
5.6.150.0100.08021.15
5.6.140.0030.07721.05
5.6.130.0100.06321.15
5.6.120.0100.06720.91
5.6.110.0070.04020.99
5.6.100.0000.04720.97
5.6.90.0030.09321.00
5.6.80.0070.04020.46
5.6.70.0100.06320.49
5.6.60.0100.07320.30
5.6.50.0100.07720.50
5.6.40.0170.07720.37
5.6.30.0070.08020.43
5.6.20.0100.07320.38
5.6.10.0230.06320.38
5.6.00.0130.08020.25
5.5.380.0030.04020.46
5.5.370.0000.05020.48
5.5.360.0070.04020.41
5.5.350.0030.04720.45
5.5.340.0100.04020.78
5.5.330.0030.04720.76
5.5.320.0070.04320.82
5.5.310.0100.08020.86
5.5.300.0070.04720.81
5.5.290.0030.04720.91
5.5.280.0100.07720.81
5.5.270.0100.03720.73
5.5.260.0000.07720.70
5.5.250.0030.08320.70
5.5.240.0000.08320.20
5.5.230.0100.07720.27
5.5.220.0000.08720.11
5.5.210.0030.05720.25
5.5.200.0100.07720.16
5.5.190.0100.07720.06
5.5.180.0030.05320.20
5.5.160.0030.08320.19
5.5.150.0070.07720.16
5.5.140.0070.07320.21
5.5.130.0100.05720.06
5.5.120.0070.07319.98
5.5.110.0070.05020.19
5.5.100.0130.08320.00
5.5.90.0170.06719.98
5.5.80.0000.08020.10
5.5.70.0070.04720.13
5.5.60.0030.07720.14
5.5.50.0070.04720.04
5.5.40.0030.08320.06
5.5.30.0070.05319.93
5.5.20.0130.07320.13
5.5.10.0070.06320.11
5.5.00.0100.08020.06
5.4.450.0070.04019.39
5.4.440.0070.06019.17
5.4.430.0030.06019.20
5.4.420.0100.04019.18
5.4.410.0030.07719.33
5.4.400.0130.04318.89
5.4.390.0070.04718.93
5.4.380.0100.07018.91
5.4.370.0070.07719.18
5.4.360.0130.05019.06
5.4.350.0070.07019.18
5.4.340.0100.07319.14
5.4.320.0000.07719.13
5.4.310.0200.05319.23
5.4.300.0070.07719.16
5.4.290.0070.08019.03
5.4.280.0130.03718.90
5.4.270.0100.04018.87
5.4.260.0170.05718.90
5.4.250.0130.07019.11
5.4.240.0070.07319.02
5.4.230.0100.07319.20
5.4.220.0100.07719.20
5.4.210.0100.07019.15
5.4.200.0070.04719.08
5.4.190.0070.04719.02
5.4.180.0030.08018.95
5.4.170.0170.03319.11
5.4.160.0170.06319.07
5.4.150.0130.07319.15
5.4.140.0070.07716.43
5.4.130.0170.05316.41
5.4.120.0030.03716.41
5.4.110.0170.03316.39
5.4.100.0200.03716.42
5.4.90.0070.06716.45
5.4.80.0100.03316.36
5.4.70.0100.05316.43
5.4.60.0000.04016.53
5.4.50.0070.05316.51
5.4.40.0100.07016.38
5.4.30.0100.06716.53
5.4.20.0070.06716.36
5.4.10.0070.04016.42
5.4.00.0130.06715.85
5.3.290.0170.06714.78
5.3.280.0170.06714.71
5.3.270.0030.07714.59
5.3.260.0130.07314.63
5.3.250.0030.05014.66
5.3.240.0030.04014.59
5.3.230.0030.07014.71
5.3.220.0000.04714.61
5.3.210.0170.06314.60
5.3.200.0100.07014.67
5.3.190.0100.07314.69
5.3.180.0200.03014.67
5.3.170.0070.07314.62
5.3.160.0070.04314.59
5.3.150.0100.04014.75
5.3.140.0070.05314.70
5.3.130.0030.04714.66
5.3.120.0100.06714.60
5.3.110.0130.05314.66
5.3.100.0000.07314.02
5.3.90.0130.04014.00
5.3.80.0170.05714.00
5.3.70.0030.08014.06
5.3.60.0030.04314.16
5.3.50.0030.06714.03
5.3.40.0030.08013.89
5.3.30.0030.06014.02
5.3.20.0070.06313.68
5.3.10.0000.07713.59
5.3.00.0070.07313.62
5.2.170.0030.05711.27
5.2.160.0030.05311.11
5.2.150.0100.03011.09
5.2.140.0070.04011.34
5.2.130.0030.06011.25
5.2.120.0030.04711.30
5.2.110.0030.04311.25
5.2.100.0030.05311.31
5.2.90.0070.05011.08
5.2.80.0100.06311.06
5.2.70.0070.06311.25
5.2.60.0030.06011.18
5.2.50.0030.06711.22
5.2.40.0000.07310.99
5.2.30.0070.04311.09
5.2.20.0030.06010.94
5.2.10.0100.05710.84
5.2.00.0000.04310.81
5.1.60.0100.04710.11
5.1.50.0100.05010.08
5.1.40.0030.05310.11
5.1.30.0100.02310.41
5.1.20.0030.06010.44
5.1.10.0000.04310.20
5.1.00.0000.05010.21
5.0.50.0000.0278.64
5.0.40.0100.0378.42
5.0.30.0000.0678.34
5.0.20.0070.0408.29
5.0.10.0030.0308.18
5.0.00.0070.0608.23
4.4.90.0000.0337.51
4.4.80.0030.0337.51
4.4.70.0070.0377.51
4.4.60.0030.0337.51
4.4.50.0030.0277.51
4.4.40.0030.0407.51
4.4.30.0000.0277.51
4.4.20.0030.0337.51
4.4.10.0170.0237.51
4.4.00.0030.0577.51
4.3.110.0100.0277.51
4.3.100.0030.0207.51
4.3.90.0030.0337.51
4.3.80.0070.0507.51
4.3.70.0000.0177.51
4.3.60.0000.0177.51
4.3.50.0000.0237.51
4.3.40.0000.0477.51
4.3.30.0000.0307.51
4.3.20.0000.0377.51
4.3.10.0070.0277.51
4.3.00.0000.0337.51

preferences:
49.85 ms | 400 KiB | 5 Q