3v4l.org

run code in 300+ PHP versions simultaneously
<?php <?php class Route { const RESOURCE_PATTERN = '/'.'\[:(.*)\]'.'/'; const TOKEN_PARA_PATTERN = '/'.'\{:(.*)\}'.'/'; private $methodList; private $url; private $urlTokenList = array(); private $urlTokenCount; private $controller; private $action; private $tokenParameterList = array(); private $tokenParameterDetailList = array(); private $resourceList = array(); private $resourceDetailList = array('music_recording' => array('jazz', 'pop')); private $requestURL; private $requestURLTokenList; private $requestURLTokenCount; public function __construct($httpMethod, $httpUrl, $controller, $action) { $this->methodList = explode('|', $httpMethod); $this->url = $httpUrl; $this->controller = $controller; $this->action = $action; $this->parseURL($httpUrl); } public function parseURL($url) { $tmpUrl = $url; if (substr($tmpUrl, 0, 1) == '/') { $tmpUrl = substr($tmpUrl, 1); } if (substr($tmpUrl, -1) == '/') { $tmpUrl = substr($tmpUrl, 0, -1); } $tmpURLTokenList = explode('/', $tmpUrl); $this->urlTokenCount = count($tmpURLTokenList); foreach($tmpURLTokenList as $token) { $tokenInfo = array(); $tokenInfo['name'] = $token; $isMatchedForResourcePattern = preg_match(self::RESOURCE_PATTERN, $token, $resourceMatches, PREG_OFFSET_CAPTURE); if ($isMatchedForResourcePattern === 1) { array_push($this->resourceList, $resourceMatches[1][0]); $tokenInfo['isResource'] = 1; $tokenInfo['resourceName'] = $resourceMatches[1][0]; } else { $tokenInfo['isResource'] = 0; } $isMatchedForParaPattern = preg_match(self::TOKEN_PARA_PATTERN, $token, $paramMatches, PREG_OFFSET_CAPTURE); if ($isMatchedForParaPattern === 1) { array_push($this->tokenParameterList, $paramMatches[1][0]); $tokenInfo['isParam'] = 1; $tokenInfo['paramName'] = $paramMatches[1][0]; } else { $tokenInfo['isParam'] = 0; } array_push($this->urlTokenList, $tokenInfo); } } public function parseRequestURL($url) { $tmpUrl = $url; if (substr($tmpUrl, 0, 1) == '/') { $tmpUrl = substr($tmpUrl, 1); } if (substr($tmpUrl, -1) == '/') { $tmpUrl = substr($tmpUrl, 0, -1); } $this->requestURLTokenList = explode('/', $tmpUrl); $this->requestURLTokenCount = count($this->requestURLTokenList); } public function getMethodList() { return $this->methodList; } public function getUrl() { return $this->url; } public function getUrlTokenList() { return $this->urlTokenList; } public function getUrlTokenCount() { return $this->urlTokenCount; } public function getController() { return $this->controller; } public function getAction() { return $this->action; } public function getTokenParameterList() { return $this->tokenParameterList; } public function getResourceList() { return $this->resourceList; } public function getResourceDetailList() { return $this->resourceDetailList; } public function isMatched($url) { $this->requestURL = $url; $this->parseRequestURL($url); // echo "count not the same[".$this->requestURLTokenCount." - ".$this->urlTokenCount."]"; if ($this->requestURLTokenCount !== $this->urlTokenCount) { // echo "count not the same[".$this->requestURLTokenCount." - ".$this->urlTokenCount."]"; return 0; } $isMatched = 1; for($i=0;$i<($this->urlTokenCount);$i++) { $urlToken = $this->urlTokenList[$i]; $requestURLToken = $this->requestURLTokenList[$i]; if ($urlToken['isResource'] !== 1 && $urlToken['isParam'] !== 1) { if (strcmp($urlToken['name'], $requestURLToken)) { $isMatched = 0; break; } } else if ($urlToken['isResource'] === 1) { if (array_key_exists($requestURLToken, $this->resourceDetailList) && in_array($requestURLToken, $this->resourceDetailList[$urlToken['resourceName']])) { $isMatched = 1; } else { $isMatched = 0; break; } } else if ($urlToken['isParam'] === 1) { $this->tokenParameterDetailList[$urlToken['paramName']] = $requestURLToken; } } return $isMatched; } public function getControllerInstance() { } } $ROUTES = array( array('httpMethod' => 'GET', 'url' => '[:music_category]/xml', 'controller' => 'CategoryController', 'action' => 'xml'), array('httpMethod' => 'GET', 'url' => '[:music_category]/json', 'controller' => 'CategoryController', 'action' => 'json'), array('httpMethod' => 'GET|POST', 'url' => 'xml', 'controller' => 'temp_controller', 'action' => 'xml'), array('httpMethod' => 'GET|POST', 'url' => 'json', 'controller' => 'temp_controller', 'action' => 'json'), array('httpMethod' => 'GET|POST', 'url' => 'post/[:music_category]/{:data}/xml', 'controller' => 'CategoryController', 'action' => 'post') ); $routeObjArray = array(); foreach ($ROUTES as $route) { array_push($GLOBALS['routeObjArray'], new Route($route['httpMethod'], $route['url'], $route['controller'], $route['action'])); } $testURl = "music/xml"; foreach ($routeObjArray as $abc) { print_r ($abc->isMatched($testURl) == 1 ? 'true' : 'false'); }

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)
5.4.340.0060.03312.01
5.4.320.0060.03512.50
5.4.310.0040.03912.49
5.4.300.0030.03712.50
5.4.290.0040.03812.49
5.4.280.0060.03912.39
5.4.270.0120.03812.39
5.4.260.0080.04012.39
5.4.250.0040.03912.39
5.4.240.0070.03912.39
5.4.230.0070.03612.38
5.4.220.0060.04112.38
5.4.210.0080.03312.38
5.4.200.0070.03712.38
5.4.190.0110.03312.38
5.4.180.0060.03512.38
5.4.170.0090.03712.38
5.4.160.0070.03412.38
5.4.150.0050.03612.38
5.4.140.0050.03712.07
5.4.130.0030.04112.05
5.4.120.0070.03312.02
5.4.110.0070.03212.01
5.4.100.0080.03412.02
5.4.90.0060.03712.01
5.4.80.0060.03512.01
5.4.70.0040.03512.00
5.4.60.0070.04012.01
5.4.50.0090.03412.01
5.4.40.0050.03511.99
5.4.30.0110.04012.00
5.4.20.0100.03911.98
5.4.10.0070.03511.99
5.4.00.0070.04211.48
5.3.290.0070.04312.80
5.3.280.0100.03412.71
5.3.270.0080.04012.73
5.3.260.0060.03912.72
5.3.250.0040.03812.72
5.3.240.0030.03912.72
5.3.230.0070.03712.70
5.3.220.0070.03612.68
5.3.210.0060.03812.68
5.3.200.0070.03512.68
5.3.190.0080.03512.68
5.3.180.0110.03012.68
5.3.170.0040.03812.67
5.3.160.0080.03312.67
5.3.150.0070.03612.68
5.3.140.0060.03512.66
5.3.130.0040.03912.66
5.3.120.0050.03812.65
5.3.110.0090.03712.66
5.3.100.0070.04212.12
5.3.90.0110.03012.09
5.3.80.0090.03912.07
5.3.70.0090.03912.08
5.3.60.0060.03712.07
5.3.50.0140.03512.00
5.3.40.0080.03812.00
5.3.30.0030.04211.95
5.3.20.0100.03811.73
5.3.10.0060.03411.70
5.3.00.0040.03611.68
5.2.170.0030.0319.18
5.2.160.0030.0309.18
5.2.150.0070.0289.19
5.2.140.0050.0299.18
5.2.130.0040.0299.14
5.2.120.0080.0259.14
5.2.110.0060.0279.15
5.2.100.0040.0279.15
5.2.90.0060.0279.15
5.2.80.0070.0279.14
5.2.70.0070.0279.14
5.2.60.0090.0249.10
5.2.50.0030.0319.06
5.2.40.0060.0279.04
5.2.30.0040.0299.01
5.2.20.0050.0279.01
5.2.10.0050.0268.93
5.2.00.0110.0248.79
5.1.60.0030.0258.08
5.1.50.0070.0228.07
5.1.40.0080.0218.05
5.1.30.0070.0238.41
5.1.20.0070.0258.42
5.1.10.0040.0258.15
5.1.00.0030.0258.14
5.0.50.0040.0196.63
5.0.40.0030.0196.48
5.0.30.0050.0296.29
5.0.20.0040.0186.27
5.0.10.0010.0216.24
5.0.00.0070.0266.23
4.4.90.0050.0134.78
4.4.80.0040.0134.75
4.4.70.0040.0144.75
4.4.60.0050.0154.75
4.4.50.0040.0144.77
4.4.40.0020.0284.70
4.4.30.0080.0164.76
4.4.20.0020.0204.84
4.4.10.0040.0214.84
4.4.00.0050.0274.76
4.3.110.0020.0164.67
4.3.100.0020.0224.67
4.3.90.0030.0144.63
4.3.80.0010.0264.59
4.3.70.0060.0154.63
4.3.60.0030.0164.63
4.3.50.0030.0154.62
4.3.40.0020.0284.54
4.3.30.0030.0143.28
4.3.20.0020.0153.26
4.3.10.0030.0173.23
4.3.00.0000.0237.40

preferences:
142.73 ms | 1394 KiB | 7 Q