3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Test; class Expression { private $closure; public function getClosure() { return $this->closure; } public function setClosure(\Closure $closure) { $this->closure = $closure; } public function getReflection() { return new \ReflectionFunction($this->getClosure()); } private function getLines() { $reflection = $this->getReflection(); $startLine = $reflection->getStartLine(); $endLine = $reflection->getEndLine(); return array_slice(file($reflection->getFileName()), $startLine - 1, ($endLine - $startLine) + 1); } private function getAllTokens(array $lines) { $code = sprintf('<?php %s ;', implode($lines)); return array_map(function ($token) { if (is_array($token)) { list($id, $value) = $token; return new Token($id, $value); } return new Token(T_SYMBOL, $token); }, array_filter(token_get_all($code), function ($token) { if (is_array($token)) { switch ($token[0]) { case T_INLINE_HTML: case T_BAD_CHARACTER: case T_COMMENT: case T_WHITESPACE: return false; } } return true; })); } private function getFilteredTokens(array $tokens) { while (!empty($tokens)) { $token = array_shift($tokens); if ($token->getId() == T_FUNCTION) { $depth = 0; $filteredTokens = []; foreach ($tokens as $token) { $filteredTokens[] = $token; if ($token->getId() == T_SYMBOL) { switch ($token->getValue()) { case '{': $depth += 1; break; case '}': $depth -= 1; if ($depth == 0) { return $filteredTokens; } break; } } } } } return []; } public function test() { $lines = $this->getLines(); $tokens = $this->getAllTokens($lines); $filteredTokens = $this->getFilteredTokens($tokens); return $filteredTokens; } public function __construct(\Closure $closure) { $this->setClosure($closure); } } const T_SYMBOL = 1099; class Token { private $id; private $value; public function getId() { return $this->id; } private function setId($id) { $this->id = (int) $id; } public function getValue() { return $this->value; } private function setValue($value) { $this->value = (string) $value; } public function getName() { if ($this->id != 1099) { return (string) token_name($this->id); } return 'T_SYMBOL'; } public function __construct($id, $value) { $this->setId($id); $this->setValue($value); } public function __toString() { return vsprintf('%-30s %s', [ $this->getName(), $this->getValue(), ]); } } $id = 1; $password = 'foobar'; $expression = new Expression(function (User $u) use ($id, $password) { return $u->id == $id && $u->password == $password; }); foreach ($expression->test() as $token) { echo $token . PHP_EOL; } var_dump($expression->getReflection()->getStaticVariables());

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.5.30.0040.00418.33
8.5.20.0100.00816.64
8.5.10.0110.00716.72
8.5.00.0150.00819.77
8.4.180.0140.01019.77
8.4.170.0130.01023.82
8.4.160.0100.01223.84
8.4.150.0080.00516.81
8.4.140.0080.01517.88
8.4.130.0070.01417.81
8.4.120.0110.00920.83
8.4.110.0060.00218.85
8.4.100.0080.01218.84
8.4.90.0110.00920.50
8.4.80.0070.00519.00
8.4.70.0110.00918.96
8.4.60.0120.00918.96
8.4.50.0120.00918.58
8.4.40.0040.01219.49
8.4.30.0200.00017.58
8.4.20.0100.01017.61
8.4.10.0090.00017.56
8.3.300.0130.01020.85
8.3.290.0120.00918.41
8.3.280.0110.01118.43
8.3.270.0140.01116.81
8.3.260.0080.01216.45
8.3.250.0100.00917.01
8.3.240.0100.00819.09
8.3.230.0110.00916.51
8.3.220.0090.00819.04
8.3.210.0090.01116.76
8.3.200.0040.00516.48
8.3.190.0100.00617.11
8.3.180.0090.00918.96
8.3.170.0090.00916.85
8.3.160.0070.00717.45
8.3.150.0130.00619.21
8.3.140.0110.00719.02
8.3.130.0090.00018.13
8.3.120.0100.01016.95
8.3.110.0070.01416.72
8.3.100.0060.00316.73
8.3.90.0100.00026.77
8.3.80.0040.00418.43
8.3.70.0060.01316.88
8.3.60.0090.00618.43
8.3.50.0090.00922.03
8.3.40.0120.00318.83
8.3.30.0120.00318.71
8.3.20.0080.00018.73
8.3.10.0040.00421.07
8.3.00.0080.00019.81
8.2.300.0170.00617.96
8.2.290.0080.01219.14
8.2.280.0130.00718.54
8.2.270.0000.01818.53
8.2.260.0090.00916.60
8.2.250.0030.00618.66
8.2.240.0100.01018.87
8.2.230.0000.00920.94
8.2.220.0060.00324.06
8.2.210.0060.00326.77
8.2.200.0030.00618.41
8.2.190.0070.01418.54
8.2.180.0100.00725.92
8.2.170.0120.00322.96
8.2.160.0100.00320.34
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0050.00319.96
8.2.110.0040.00422.27
8.2.100.0040.00717.84
8.2.90.0050.00317.75
8.2.80.0060.00318.78
8.2.70.0000.00817.63
8.2.60.0060.00317.63
8.2.50.0040.00417.75
8.2.40.0000.00819.62
8.2.30.0000.00817.68
8.2.20.0000.00817.82
8.2.10.0030.00617.94
8.2.00.0040.00717.88
8.1.340.0080.01317.85
8.1.330.0090.01116.08
8.1.320.0040.00618.03
8.1.310.0150.00016.79
8.1.300.0060.00320.33
8.1.290.0040.01130.84
8.1.280.0110.00425.92
8.1.270.0080.00023.99
8.1.260.0070.01126.35
8.1.250.0000.00728.09
8.1.240.0080.00023.83
8.1.230.0100.00019.29
8.1.220.0040.00417.80
8.1.210.0030.00618.77
8.1.200.0030.00717.60
8.1.190.0090.00017.65
8.1.180.0000.00818.10
8.1.170.0050.00317.78
8.1.160.0000.00818.96
8.1.150.0040.00418.75
8.1.140.0030.00517.51
8.1.130.0040.00417.43
8.1.120.0040.00417.42
8.1.110.0040.00417.42
8.1.100.0080.00017.55
8.1.90.0030.00517.50
8.1.80.0080.00017.52
8.1.70.0040.00417.45
8.1.60.0000.00917.64
8.1.50.0000.00817.61
8.1.40.0000.00917.50
8.1.30.0030.00617.69
8.1.20.0000.00817.54
8.1.10.0030.00517.62
8.1.00.0000.00917.58
8.0.300.0050.00318.77
8.0.290.0030.00516.75
8.0.280.0030.00618.09
8.0.270.0090.00018.05
8.0.260.0000.00716.86
8.0.250.0050.00317.15
8.0.240.0030.00517.12
8.0.230.0000.00717.10
8.0.220.0070.00017.06
8.0.210.0040.00416.90
8.0.200.0000.00717.12
8.0.190.0040.00417.09
8.0.180.0080.00016.96
8.0.170.0000.00817.03
8.0.160.0040.00417.01
8.0.150.0040.00416.93
8.0.140.0030.00516.86
8.0.130.0000.00713.43
8.0.120.0080.00016.95
8.0.110.0040.00416.88
8.0.100.0030.00517.05
8.0.90.0040.00417.06
8.0.80.0140.00317.06
8.0.70.0040.00416.93
8.0.60.0030.00517.13
8.0.50.0000.00817.05
8.0.30.0070.01217.33
8.0.20.0080.01217.40
8.0.10.0000.00717.13
8.0.00.0130.00916.92
7.4.330.0050.00016.67
7.4.320.0000.00616.49
7.4.300.0000.00616.56
7.4.290.0070.00016.65
7.4.280.0000.00716.59
7.4.270.0030.00316.68
7.4.260.0030.00313.39
7.4.250.0000.00816.48
7.4.240.0070.00016.59
7.4.230.0000.00816.64
7.4.220.0150.00316.46
7.4.210.0070.00816.61
7.4.200.0000.00716.46
7.4.190.0030.00516.57
7.4.160.0030.01416.48
7.4.150.0150.00417.40
7.4.140.0100.01117.86
7.4.130.0090.00916.56
7.4.120.0100.01216.60
7.4.110.0120.00916.60
7.4.100.0090.00916.54
7.4.90.0080.01216.54
7.4.80.0140.01019.39
7.4.70.0160.01316.36
7.4.60.0030.01516.70
7.4.50.0050.00316.64
7.4.40.0080.00822.77
7.4.30.0070.01116.54
7.4.00.0060.00915.08
7.3.330.0000.00613.35
7.3.320.0030.00313.29
7.3.310.0000.00716.46
7.3.300.0000.00716.51
7.3.290.0070.01416.55
7.3.280.0070.01016.46
7.3.270.0120.00617.40
7.3.260.0090.01318.24
7.3.250.0190.00816.46
7.3.240.0170.01016.76
7.3.230.0070.01116.57
7.3.210.0120.01216.63
7.3.200.0130.00719.39
7.3.190.0110.01116.58
7.3.180.0100.00716.43
7.3.170.0070.01016.60
7.3.160.0090.00916.63
7.3.120.0060.00915.16
7.2.330.0090.01916.56
7.2.320.0160.00316.70
7.2.310.0150.00416.51
7.2.300.0030.01416.85
7.2.290.0110.00716.87
7.2.60.0060.00316.95
7.1.200.0060.00615.88
7.1.70.0090.00617.25
7.1.60.0000.01917.25
7.1.50.0080.00816.67
7.1.40.0040.00816.78
7.1.30.0090.00416.75
7.1.20.0090.00316.82
7.1.10.0020.00716.80
7.1.00.0030.01316.69
7.0.200.0110.00416.74
7.0.190.0030.00816.65
7.0.180.0070.00316.32
7.0.170.0000.01216.58
7.0.160.0000.01116.22
7.0.150.0050.00716.47
7.0.140.0000.00816.29
7.0.130.0100.00016.54
7.0.120.0040.00816.75
7.0.110.0060.00316.50
7.0.100.0080.00316.27
7.0.90.0000.00816.34
7.0.80.0050.00516.41
7.0.70.0000.00916.66
7.0.60.0030.00916.26
7.0.50.0040.00416.48
7.0.40.0040.00415.66
7.0.30.0000.01115.66
7.0.20.0000.01015.66
7.0.10.0050.00315.66
7.0.00.0030.00815.66
5.6.300.0100.04320.85
5.6.290.0000.05520.87
5.6.280.0030.04920.86
5.6.270.0030.04020.82
5.6.260.0200.04621.02
5.6.250.0040.04621.07
5.6.240.0000.04820.98
5.6.230.0060.03920.86
5.6.220.0030.04020.81
5.6.210.0030.04621.07
5.6.200.0070.03820.78
5.6.190.0000.05520.90
5.6.180.0000.04520.98
5.6.170.0030.04721.07
5.6.160.0030.04820.84
5.6.150.0030.05020.86
5.6.140.0030.04620.96
5.6.130.0000.04820.87
5.6.120.0070.03720.78
5.6.110.0300.04321.07
5.6.100.0170.06620.85
5.6.90.0030.07820.87
5.6.80.0030.05120.16
5.6.70.0000.04420.23
5.6.60.0200.04420.40
5.6.50.0060.07720.25
5.6.40.0070.03620.43
5.6.30.0000.04320.38
5.6.20.0070.04720.21
5.6.10.0030.06720.38
5.6.00.0040.03920.36
5.5.380.0000.04717.48
5.5.370.0030.04717.66
5.5.360.0040.03917.66
5.5.350.0000.04117.61
5.5.340.0130.04318.16
5.5.330.0000.05218.14
5.5.320.0070.04718.15
5.5.310.0030.04118.09
5.5.300.0030.04218.14
5.5.290.0030.04318.22
5.5.280.0070.04418.05
5.5.270.0030.04018.11
5.5.260.0030.08418.14
5.5.250.0030.05317.89
5.5.240.0240.04017.51
5.5.230.0000.05017.50
5.5.220.0100.03017.53
5.5.210.0030.04517.27
5.5.200.0030.08117.45
5.5.190.0100.03617.39
5.5.180.0060.03617.48
5.5.160.0100.03317.56
5.5.150.0030.03917.12
5.5.140.0030.04317.39
5.5.130.0100.04517.42
5.5.120.0030.04717.48
5.5.110.0070.03517.23
5.5.100.0030.06317.14
5.5.90.0000.05417.34
5.5.80.0030.03717.39
5.5.70.0060.03517.13
5.5.60.0070.06617.33
5.5.50.0070.07017.38
5.5.40.0070.06617.41
5.5.30.0030.03917.45
5.5.20.0000.04317.45
5.5.10.0070.03717.28
5.5.00.0030.05117.28
5.4.450.0030.04019.41
5.4.440.0000.05019.53
5.4.430.0030.04819.38
5.4.420.0100.03519.24
5.4.410.0000.05019.41
5.4.400.0070.03919.12
5.4.390.0070.03919.14
5.4.380.0000.03919.17
5.4.370.0030.03718.97
5.4.360.0070.04019.12
5.4.350.0000.04718.98
5.4.340.0000.04419.14
5.4.320.0030.03819.18
5.4.310.0030.04019.24
5.4.300.0030.03818.94
5.4.290.0100.07219.16
5.4.280.0030.03919.09
5.4.270.0030.05218.99
5.4.260.0030.06819.20
5.4.250.0030.04019.07
5.4.240.0100.04919.10
5.4.230.0000.06519.11
5.4.220.0030.03819.13
5.4.210.0000.04019.17
5.4.200.0240.03718.96
5.4.190.0070.05919.13
5.4.180.0190.03919.20
5.4.170.0130.03919.06
5.4.160.0040.03619.18
5.4.150.0030.04119.21
5.4.140.0100.03616.55
5.4.130.0100.04616.54
5.4.120.0030.03616.54
5.4.110.0030.08716.54
5.4.100.0030.03316.69
5.4.90.0030.03516.80
5.4.80.0030.03516.61
5.4.70.0070.04916.80
5.4.60.0030.03616.51
5.4.50.0000.04716.52
5.4.40.0070.05416.73
5.4.30.0030.04116.66
5.4.20.0030.04316.66
5.4.10.0000.05516.77
5.4.00.0030.07116.26
5.3.290.0000.04115.66
5.3.280.0000.04115.66
5.3.270.0000.06015.66
5.3.260.0070.06015.66
5.3.250.0030.03815.66
5.3.240.0070.07315.66
5.3.230.0060.05515.66
5.3.220.0030.03715.66
5.3.210.0000.04015.66
5.3.200.0000.04015.66
5.3.190.0040.03515.66
5.3.180.0000.04415.66
5.3.170.0060.06115.66
5.3.160.0030.07315.66
5.3.150.0100.02815.66
5.3.140.0000.06615.66
5.3.130.0030.04015.66
5.3.120.0070.03315.66
5.3.110.0000.08015.66
5.3.100.0000.04015.66
5.3.90.0000.04115.66
5.3.80.0030.03915.66
5.3.70.0140.03115.66
5.3.60.0000.05415.66
5.3.50.0000.03715.66
5.3.40.0040.04015.66
5.3.30.0030.03415.66
5.3.20.0070.07315.66
5.3.10.0030.03315.66
5.3.00.0030.05615.66
5.2.170.0030.03715.66
5.2.160.0030.03015.66
5.2.150.0060.02615.66
5.2.140.0070.05315.66
5.2.130.0200.03015.66
5.2.120.0030.04215.66
5.2.110.0030.05615.66
5.2.100.0030.02815.66
5.2.90.0070.05615.66
5.2.80.0000.04514.79
5.2.70.0060.03214.79
5.2.60.0030.05214.79
5.2.50.0000.03214.79
5.2.40.0070.02314.79
5.2.30.0070.02414.79
5.2.20.0030.02714.79
5.2.10.0070.02214.79
5.2.00.0030.05014.79
5.1.60.0070.05314.79
5.1.50.0070.05414.79
5.1.40.0060.04414.79
5.1.30.0030.04814.79
5.1.20.0030.02814.79
5.1.10.0060.05114.79
5.1.00.0030.05814.79
5.0.50.0100.01714.79
5.0.40.0000.02714.79
5.0.30.0030.02914.79
5.0.20.0000.02314.79
5.0.10.0090.01814.79
5.0.00.0000.03614.79
4.4.90.0000.01614.79
4.4.80.0030.01314.79
4.4.70.0030.02514.79
4.4.60.0030.01314.79
4.4.50.0000.01914.79
4.4.40.0070.03014.79
4.4.30.0030.01614.79
4.4.20.0040.03214.79
4.4.10.0030.01514.79
4.4.00.0000.02614.79
4.3.110.0000.03214.79
4.3.100.0000.01614.79
4.3.90.0000.02414.79
4.3.80.0060.01914.79
4.3.70.0000.01514.79
4.3.60.0030.01814.79
4.3.50.0030.01514.79
4.3.40.0060.01914.79
4.3.30.0030.01714.79
4.3.20.0000.01714.79
4.3.10.0030.02414.79
4.3.00.0030.01714.79

preferences:
107.17 ms | 3004 KiB | 5 Q