3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo Templation::Run("hello {{world}} how are {{you}}", $data = array('world'=>'WORLD!', 'you'=>'YOU!')); class Templation { /** * Mark the templated variable with a special class in html so javascript can use it also. * @param $match * @param $replace_with * @return string */ private static function enclose($match, $replace_with){ return '<span class="Templation" title='.json_encode(htmlentities($match)).' data-Templation='.json_encode(htmlentities($match)).'>'.$replace_with.'</span>'; } /** * Run the template through with the given data and return a result * optionally enclosing each replacement with a <span class="Templation"> * For the JavaScript version to run correctly. * @see Templation.js * * @param $template * @param $data * @return string */ public static function Run($template, $data, $enclose = true){ $result = $template; preg_match_all('/{{([^}]+?)}}/im', $template, $matches, PREG_PATTERN_ORDER); $matches = $matches[0]; foreach($matches as $i => $match){ if (strpos($match, '||') !== false){ $replace_with = self::PriorityReplace($match, $data); $result = str_replace($match, $enclose ? self::enclose($match, $replace_with) : $replace_with, $result); }else{ $match2 = preg_replace("/(\\{\\{|\\}\\})/", "", $match); if (isset($data[$match2])){ $result = str_replace($match, $enclose ? self::enclose($match, $data[$match2]) : $data[$match2], $result); }else{ $result = str_replace($match, $enclose ? self::enclose($match, $match) : $match, $result); } } } return $result; } /** * Do a Priority Replacement based on the fact that there is || as a delimiter * This means that currently literal text with a '||' is not supported * for example {{var5||var4||var3||'Hello || World'}} will break it. (too many features would slow it down) * * @param $match * @param $data * @return mixed|string */ public static function PriorityReplace($match, $data){ $match = preg_replace("/(\\{\\{|\\}\\})/", "", $match); $p = explode('||', $match); //var_dump($p); for($i = 0; $i < count($p); ++$i){ if (strpos($p[$i], '\'') !== false){ return trim($p[$i],"'"); } else if (isset($data[$p[$i]])){ return $data[$p[$i]]; } } return $match; } }

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.0100.00716.74
8.3.50.0060.00916.76
8.3.40.0160.00018.82
8.3.30.0060.00918.92
8.3.20.0040.00420.20
8.3.10.0040.00421.90
8.3.00.0000.00820.74
8.2.180.0120.00618.54
8.2.170.0140.00722.96
8.2.160.0120.00322.32
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0070.00022.21
8.2.120.0050.00226.35
8.2.110.0070.00322.30
8.2.100.0120.00018.16
8.2.90.0030.00619.17
8.2.80.0080.00417.97
8.2.70.0060.00317.75
8.2.60.0040.00417.90
8.2.50.0030.00618.10
8.2.40.0080.00022.35
8.2.30.0030.00521.00
8.2.20.0080.00018.08
8.2.10.0000.00818.26
8.2.00.0030.00518.18
8.1.280.0150.00625.92
8.1.270.0090.00023.83
8.1.260.0050.00326.35
8.1.250.0070.00728.09
8.1.240.0060.00323.79
8.1.230.0060.00617.95
8.1.220.0000.00817.91
8.1.210.0030.00618.77
8.1.200.0070.00417.48
8.1.190.0030.00517.47
8.1.180.0050.00318.10
8.1.170.0030.00618.89
8.1.160.0040.00419.03
8.1.150.0040.00420.66
8.1.140.0000.00819.59
8.1.130.0070.00018.88
8.1.120.0070.00017.66
8.1.110.0040.00417.69
8.1.100.0060.00317.66
8.1.90.0030.00517.50
8.1.80.0070.00017.70
8.1.70.0030.00317.67
8.1.60.0030.00617.79
8.1.50.0050.00317.77
8.1.40.0000.00817.74
8.1.30.0050.00317.79
8.1.20.0000.00817.75
8.1.10.0080.00017.68
8.1.00.0040.00417.61
8.0.300.0000.00818.77
8.0.290.0070.00017.00
8.0.280.0000.00718.39
8.0.270.0050.00317.18
8.0.260.0000.00716.87
8.0.250.0080.00017.18
8.0.240.0070.00017.07
8.0.230.0070.00017.16
8.0.220.0040.00417.11
8.0.210.0040.00417.10
8.0.200.0000.00817.05
8.0.190.0000.00817.04
8.0.180.0070.00017.16
8.0.170.0040.00417.18
8.0.160.0040.00417.09
8.0.150.0000.00816.96
8.0.140.0040.00417.01
8.0.130.0090.00013.55
8.0.120.0050.00317.08
8.0.110.0000.00817.09
8.0.100.0000.00716.87
8.0.90.0050.00316.98
8.0.80.0140.00417.06
8.0.70.0040.00417.02
8.0.60.0000.00817.21
8.0.50.0040.00417.15
8.0.30.0090.01017.43
8.0.20.0190.00417.40
8.0.10.0040.00417.11
8.0.00.0150.00317.22
7.4.330.0050.00015.55
7.4.320.0000.00716.77
7.4.300.0030.00316.69
7.4.290.0030.00316.77
7.4.280.0050.00216.85
7.4.270.0080.00016.84
7.4.260.0000.00816.81
7.4.250.0070.00016.75
7.4.240.0070.00016.79
7.4.230.0030.00316.89
7.4.220.0150.00316.89
7.4.210.0030.01116.82
7.4.200.0000.00716.68
7.4.160.0080.00816.87
7.4.150.0070.01117.40
7.4.140.0110.00817.86
7.4.130.0060.01516.94
7.4.120.0140.00716.67
7.4.110.0180.00416.77
7.4.100.0060.01516.94
7.4.90.0070.01016.67
7.4.80.0130.00319.39
7.4.70.0100.01216.78
7.4.60.0120.00616.91
7.4.50.0070.01016.97
7.4.40.0170.00016.72
7.4.30.0090.00916.70
7.4.00.0060.01215.20
7.3.330.0070.00013.52
7.3.320.0000.00513.63
7.3.310.0000.00816.66
7.3.300.0000.00716.57
7.3.290.0070.00016.41
7.3.280.0060.01016.56
7.3.270.0070.01017.40
7.3.260.0130.00716.73
7.3.250.0080.01216.79
7.3.240.0090.00916.81
7.3.230.0100.00716.89
7.3.210.0140.00316.79
7.3.200.0120.00916.57
7.3.190.0130.00316.73
7.3.180.0070.01016.66
7.3.170.0060.00916.75
7.3.160.0110.00816.70
7.3.120.0050.01215.22
7.3.110.0100.00715.05
7.3.100.0110.00315.21
7.3.90.0000.01114.89
7.3.80.0110.00515.26
7.3.70.0070.00615.16
7.3.60.0090.00514.91
7.3.50.0030.01014.93
7.3.40.0060.00814.81
7.3.30.0030.00815.05
7.3.20.0090.00516.59
7.3.10.0070.00716.77
7.3.00.0030.00816.78
7.2.330.0120.00616.90
7.2.320.0110.00716.94
7.2.310.0100.00717.07
7.2.300.0140.00416.78
7.2.290.0180.00316.94
7.2.250.0050.01415.23
7.2.240.0040.01315.33
7.2.230.0020.01215.32
7.2.220.0060.00915.37
7.2.210.0100.00815.44
7.2.200.0070.00615.33
7.2.190.0090.00715.24
7.2.180.0050.01015.25
7.2.170.0100.00715.07
7.2.160.0120.00314.96
7.2.150.0060.00917.08
7.2.140.0040.01516.75
7.2.130.0070.00717.11
7.2.120.0030.01317.12
7.2.110.0040.01517.21
7.2.100.0090.00917.15
7.2.90.0070.01017.33
7.2.80.0070.00417.32
7.2.70.0070.01117.34
7.2.60.0060.01016.88
7.2.50.0030.01016.96
7.2.40.0090.00617.01
7.2.30.0090.00617.19
7.2.20.0040.01117.16
7.2.10.0070.00716.98
7.2.00.0030.01118.30
7.1.330.0060.00615.94
7.1.320.0080.00816.20
7.1.310.0110.00516.20
7.1.300.0060.00715.88
7.1.290.0080.00615.88
7.1.280.0040.00915.87
7.1.270.0020.01316.00
7.1.260.0050.00816.02
7.1.250.0040.00815.91
7.1.240.0030.01415.85
7.1.230.0050.00515.96
7.1.220.0130.00316.00
7.1.210.0060.00615.94
7.1.200.0050.00815.92
7.1.190.0060.01016.18
7.1.180.0070.00715.89
7.1.170.0030.00716.12
7.1.160.0030.00716.03
7.1.150.0000.00915.98
7.1.140.0070.00716.16
7.1.130.0030.01316.09
7.1.120.0070.00715.74
7.1.110.0090.00615.95
7.1.100.0410.00816.13
7.1.90.0090.00916.18
7.1.80.0070.01015.83
7.1.70.0060.01116.64
7.1.60.0290.00424.60
7.1.50.0300.01224.62
7.1.40.0470.00724.46
7.1.30.0290.01024.47
7.1.20.0420.00824.58
7.1.10.0230.00815.48
7.1.00.0250.00715.72
7.0.330.0000.01315.60
7.0.320.0030.01315.36
7.0.310.0080.00815.25
7.0.300.0040.01115.45
7.0.290.0030.01015.64
7.0.280.0060.00615.71
7.0.270.0030.01315.55
7.0.260.0090.00615.69
7.0.250.0060.00915.58
7.0.240.0140.00315.77
7.0.230.0090.00915.40
7.0.220.0070.00715.54
7.0.210.0030.00915.67
7.0.200.0230.00615.46
7.0.190.0220.00815.35
7.0.180.0220.01115.16
7.0.170.0240.00715.21
7.0.160.0210.01115.24
7.0.150.0200.00915.19
7.0.140.0190.00915.03
7.0.130.0170.00915.31
7.0.120.0180.00815.28
7.0.110.0180.00815.25
7.0.100.0120.01215.14
7.0.90.0130.01515.28
7.0.80.0170.00915.20
7.0.70.0150.00915.29
7.0.60.0180.00815.11
7.0.50.0170.01115.23
7.0.40.0190.00914.37
7.0.30.0180.00814.39
7.0.20.0190.00714.34
7.0.10.0230.00514.18
7.0.00.0200.00814.21
5.6.400.0030.00914.62
5.6.390.0000.01314.73
5.6.380.0100.00614.84
5.6.370.0070.01114.56
5.6.360.0030.01014.77
5.6.350.0100.01014.23
5.6.340.0060.01214.66
5.6.330.0060.00914.54
5.6.320.0060.00914.59
5.6.310.0070.00714.49
5.6.300.0030.01314.70
5.6.290.0030.01014.35
5.6.280.0000.01214.34
5.6.270.0090.00414.92
5.6.260.0060.00614.63
5.6.250.0040.01114.45
5.6.240.0070.00714.68
5.6.230.0060.00314.71
5.6.220.0030.00614.47
5.6.210.0100.00014.48
5.6.200.0000.01114.39
5.6.190.0110.00614.36
5.6.180.0000.00914.43
5.6.170.0090.00614.61
5.6.160.0030.00614.66
5.6.150.0000.00914.41
5.6.140.0090.00614.27
5.6.130.0080.00014.48
5.6.120.0090.00014.43
5.6.110.0070.01014.34
5.6.100.0060.00814.42
5.6.90.0000.01514.51
5.6.80.0070.00714.31
5.6.70.0000.01414.41
5.6.60.0060.00614.53
5.6.50.0030.00914.36
5.6.40.0030.00714.37
5.6.30.0120.00314.65
5.6.20.0060.00914.53
5.6.10.0150.00014.27
5.6.00.0030.01214.34

preferences:
41.05 ms | 401 KiB | 5 Q