3v4l.org

run code in 300+ PHP versions simultaneously
<?php namespace Fake\BuiltIn\Functions; /** * Executes the given statements using fake built-in functions. * * @param callable $statements Statements to execute. * @return mixed Whatever $statements returns. * @throws \ReflectionException */ function fake(callable $statements) { $function = new \ReflectionFunction($statements); $start_line = $function->getStartLine(); $end_line = $function->getEndLine(); $function_source = implode('', array_slice(file($function->getFileName()), $start_line - 1, $end_line - $start_line + 1)); if (preg_match('/(?<={).*(?=})/s', $function_source, $matches)) { $function_body = $matches[0]; $namespace = __NAMESPACE__; return eval(" namespace $namespace; $function_body "); } throw new \RuntimeException('Failed to execute statements.'); } function strlen($string) { return 'fake result'; } namespace My\Name\Space; use function Fake\BuiltIn\Functions\fake; class MyClass { /** * @throws \ReflectionException */ public function testMethodWithFakeStrlen() { fake(function () { echo strlen('foo'), PHP_EOL; }); } public function testMethodWithoutFakeStrlen() { echo strlen('foo'), PHP_EOL; } } $myObject = new MyClass(); try { $myObject->testMethodWithFakeStrlen(); $myObject->testMethodWithoutFakeStrlen(); } catch (\ReflectionException $e) { // ... }

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.70.0140.00717.00
8.3.60.0070.01118.43
8.3.50.0000.01418.25
8.3.40.0200.00318.93
8.3.30.0040.01218.77
8.3.20.0040.00420.73
8.3.10.0090.00023.55
8.3.00.0080.00022.45
8.2.190.0120.00318.34
8.2.180.0130.00318.41
8.2.170.0090.00622.96
8.2.160.0100.00322.25
8.2.150.0070.00724.18
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0060.00319.40
8.2.110.0060.00321.06
8.2.100.0060.00617.82
8.2.90.0040.00417.75
8.2.80.0000.01017.97
8.2.70.0080.00017.88
8.2.60.0050.00318.16
8.2.50.0060.00318.10
8.2.40.0000.00821.15
8.2.30.0050.00219.31
8.2.20.0040.00718.19
8.2.10.0000.00819.25
8.2.00.0000.00718.25
8.1.280.0090.00625.92
8.1.270.0000.00823.86
8.1.260.0030.00526.35
8.1.250.0000.00728.09
8.1.240.0030.00619.42
8.1.230.0110.00017.95
8.1.220.0040.00417.79
8.1.210.0030.00518.77
8.1.200.0030.00617.73
8.1.190.0000.00817.48
8.1.180.0050.00318.10
8.1.170.0050.00318.78
8.1.160.0000.00718.91
8.1.150.0040.00418.84
8.1.140.0050.00320.23
8.1.130.0040.00417.60
8.1.120.0000.00717.64
8.1.110.0090.00017.55
8.1.100.0000.00717.52
8.1.90.0000.00717.60
8.1.80.0070.00017.55
8.1.70.0080.00317.59
8.1.60.0050.00317.81
8.1.50.0040.00417.62
8.1.40.0060.00317.71
8.1.30.0090.00017.79
8.1.20.0030.00617.82
8.1.10.0040.00417.67
8.1.00.0000.00917.74
8.0.300.0000.00718.77
8.0.290.0040.00417.00
8.0.280.0000.00718.53
8.0.270.0040.00417.08
8.0.260.0040.00417.02
8.0.250.0000.00717.26
8.0.240.0060.00317.18
8.0.230.0050.00217.20
8.0.220.0070.00017.09
8.0.210.0030.00317.19
8.0.200.0050.00317.24
8.0.190.0070.00017.26
8.0.180.0050.00317.18
8.0.170.0050.00517.06
8.0.160.0020.00517.11
8.0.150.0040.00317.16
8.0.140.0000.00817.17
8.0.130.0060.00013.56
8.0.120.0030.00517.16
8.0.110.0080.00017.07
8.0.100.0050.00317.04
8.0.90.0040.00417.21
8.0.80.0080.01517.19
8.0.70.0050.00316.95
8.0.60.0030.00517.14
8.0.50.0040.00417.18
8.0.30.0080.01017.12
8.0.20.0090.00917.34
8.0.10.0000.00717.18
8.0.00.0110.01117.05
7.4.330.0020.00215.55
7.4.320.0070.00016.78
7.4.300.0030.00316.69
7.4.290.0030.00316.79
7.4.280.0060.00316.67
7.4.270.0000.00716.78
7.4.260.0000.00716.86
7.4.250.0030.00516.68
7.4.240.0040.00416.73
7.4.230.0030.00516.89
7.4.220.0070.00016.79
7.4.210.0090.00616.93
7.4.200.0070.00016.66
7.4.160.0140.00516.81
7.4.140.0130.00617.86
7.4.130.0110.01116.75
7.4.120.0110.00916.89
7.4.110.0100.00616.81
7.4.100.0110.00716.56
7.4.90.0110.00816.70
7.4.80.0120.00619.39
7.4.70.0140.00716.88
7.4.60.0060.01016.80
7.4.50.0030.01016.70
7.4.40.0130.00416.64
7.4.00.0000.01515.16
7.3.330.0050.00013.52
7.3.320.0000.00613.58
7.3.310.0030.00316.60
7.3.300.0000.00716.49
7.3.290.0030.00616.59
7.3.280.0130.00316.54
7.3.260.0090.00916.63
7.3.240.0120.00816.78
7.3.230.0070.01016.78
7.3.210.0100.00716.76
7.3.200.0030.01316.81
7.3.190.0140.00316.53
7.3.180.0130.00616.61
7.3.170.0070.01316.89
7.3.160.0000.01616.82
7.3.120.0070.01315.30
7.3.110.0110.00715.02
7.3.100.0070.01015.11
7.3.90.0060.00914.89
7.3.80.0070.00715.02
7.3.70.0030.01015.08
7.3.60.0120.00315.13
7.3.50.0030.01315.14
7.3.40.0090.00814.92
7.3.30.0060.01114.91
7.3.20.0300.00815.85
7.3.10.0200.01615.75
7.3.00.0240.00815.82
7.2.330.0070.01116.94
7.2.320.0030.01416.96
7.2.310.0070.01016.95
7.2.300.0060.01216.96
7.2.290.0100.01017.02
7.2.250.0090.01215.23
7.2.240.0140.00715.54
7.2.230.0090.00615.06
7.2.220.0070.00315.45
7.2.210.0070.01315.38
7.2.200.0070.00715.39
7.2.190.0070.00715.00
7.2.180.0120.00615.11
7.2.170.0030.01015.51
7.2.160.0140.00015.43
7.2.150.0420.00615.41
7.2.140.1700.01315.29
7.2.130.0260.01115.28
7.2.120.0340.01015.53
7.2.110.0380.00615.25
7.2.100.0560.01015.26
7.2.90.0500.01415.22
7.2.80.0380.00315.39
7.2.70.0460.01014.99
7.2.60.0440.00815.22
7.2.50.0530.00015.24
7.2.40.0450.00615.26
7.2.30.0140.00915.20
7.2.20.0430.00715.27
7.2.10.0400.00615.43
7.2.00.0300.01015.38
7.1.330.0040.00716.11
7.1.320.0000.00915.65
7.1.310.0030.01315.88
7.1.300.0030.01316.02
7.1.290.0110.00816.21
7.1.280.0000.01215.94
7.1.270.0320.00915.02
7.1.260.0070.01014.90
7.1.250.0090.00514.10

preferences:
16.48 ms | 401 KiB | 5 Q