3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Filter { abstract public static function check($value, array $options = array()); } final class IntFilter { public static function check($value, array $options = array()) { return $value; } } final class StringFilter { public static function check($value, array $options = array()) { if (false === is_string($value)) { return false; } if (false !== ($options['trim'] ?? true)) { $value = trim($value); } $length = mb_strlen($value, '8bit'); if ((false === ($options['empty'] ?? true)) && (0 === $length)) { return false; } if (isset($options['max'])) { $maxLength = IntFilter::check($options['max'], ['min' => 1]); if ($length > $maxLength) { return false; } } if (isset($options['min'])) { $minLength = IntFilter::check($options['min'], ['min' => 1]); if ($length < $minLength) { return false; } } foreach (['startsWith', 'endsWith'] as $name) { if (isset($options[$name])) { $needle = StringFilter::check($options[$name]); if (false === self::$name($value, $needle)) { return false; } } } return $value; } private static function startsWith($haystack, $needle) { return $haystack[0] === $needle[0] ? strncmp($haystack, $needle, mb_strlen($needle, '8bit')) === 0 : false; } private static function endsWith($haystack, $needle) { $length = mb_strlen($needle, '8bit'); $haystack = mb_substr($haystack, -$length); return $haystack[0] === $needle[0] ? strncmp($haystack, $needle, $length) === 0 : false; } } var_dump(StringFilter::check(' r a ', ['startsWith' => 'r']));

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.0120.00318.20
8.3.60.0110.01118.56
8.3.50.0090.00817.47
8.3.40.0090.00918.82
8.3.30.0140.00718.67
8.3.20.0070.01119.01
8.3.10.0080.00021.62
8.3.00.0030.00520.77
8.2.180.0000.01518.25
8.2.170.0180.00022.96
8.2.160.0090.00622.11
8.2.150.0000.00825.66
8.2.140.0040.00424.66
8.2.130.0000.00822.13
8.2.120.0040.00426.35
8.2.110.0070.00320.25
8.2.100.0110.00017.97
8.2.90.0080.00019.18
8.2.80.0000.00817.97
8.2.70.0050.00517.75
8.2.60.0080.00018.03
8.2.50.0000.00818.10
8.2.40.0000.00822.27
8.2.30.0040.00419.29
8.2.20.0040.00418.08
8.2.10.0070.00018.22
8.2.00.0040.00418.14
8.1.280.0140.00325.92
8.1.270.0000.00823.97
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0030.00622.66
8.1.230.0070.00419.22
8.1.220.0080.00017.74
8.1.210.0080.00018.77
8.1.200.0070.00317.22
8.1.190.0040.00417.23
8.1.180.0000.00918.10
8.1.170.0030.00518.48
8.1.160.0080.00018.98
8.1.150.0050.00318.81
8.1.140.0060.00319.63
8.1.130.0040.00418.94
8.1.120.0040.00417.57
8.1.110.0040.00417.46
8.1.100.0020.00517.49
8.1.90.0060.00317.46
8.1.80.0000.00717.47
8.1.70.0000.00717.55
8.1.60.0050.00317.67
8.1.50.0080.00017.56
8.1.40.0040.00417.66
8.1.30.0070.00017.62
8.1.20.0040.00417.77
8.1.10.0000.00717.65
8.1.00.0000.00817.53
8.0.300.0040.00418.77
8.0.290.0000.00716.88
8.0.280.0070.00018.58
8.0.270.0000.00817.30
8.0.260.0070.00016.94
8.0.250.0000.00816.96
8.0.240.0040.00417.07
8.0.230.0040.00417.02
8.0.220.0030.00316.97
8.0.210.0000.00716.96
8.0.200.0000.00616.95
8.0.190.0060.00316.96
8.0.180.0050.00216.95
8.0.170.0040.00416.93
8.0.160.0030.00316.89
8.0.150.0080.00016.95
8.0.140.0020.00516.82
8.0.130.0000.00613.39
8.0.120.0070.00016.97
8.0.110.0000.01016.91
8.0.100.0070.00016.99
8.0.90.0040.00416.82
8.0.80.0000.01517.04
8.0.70.0000.00716.86
8.0.60.0080.00016.97
8.0.50.0050.00316.90
8.0.30.0100.00917.09
8.0.20.0110.01417.40
8.0.10.0050.00316.91
8.0.00.0000.02016.99
7.4.330.0020.00215.55
7.4.320.0060.00016.66
7.4.300.0000.00616.65
7.4.290.0000.00816.62
7.4.280.0000.00716.68
7.4.270.0030.00316.64
7.4.260.0000.00513.25
7.4.250.0060.00316.52
7.4.240.0040.00416.66
7.4.230.0030.00316.63
7.4.220.0150.00316.47
7.4.210.0050.01016.56
7.4.200.0030.00316.67
7.4.160.0090.01016.71
7.4.150.0160.00317.40
7.4.140.0150.00717.86
7.4.130.0130.01316.37
7.4.120.0110.00916.63
7.4.110.0090.00916.58
7.4.100.0080.01616.60
7.4.90.0150.00816.71
7.4.80.0120.00919.39
7.4.70.0070.00916.47
7.4.60.0070.01016.57
7.4.50.0040.01116.66
7.4.40.0090.00616.55
7.4.30.0230.02716.38
7.4.00.0070.01114.88
7.3.330.0050.00013.32
7.3.320.0000.00613.41
7.3.310.0040.00416.39
7.3.300.0000.00716.27
7.3.290.0030.00316.31
7.3.280.0070.00916.35
7.3.270.0160.00817.40
7.3.260.0080.01216.51
7.3.250.0100.01016.44
7.3.240.0100.00716.30
7.3.230.0060.01216.30
7.3.210.0140.00316.44
7.3.200.0060.01616.41
7.3.190.0060.01016.29
7.3.180.0110.00616.39
7.3.170.0070.01016.42
7.3.160.0150.00016.40
7.3.10.0030.00816.84
7.3.00.0040.00416.48
7.2.330.0070.01016.80
7.2.320.0090.00916.80
7.2.310.0130.00416.57
7.2.300.0030.01516.84
7.2.290.0130.00416.69
7.2.130.0000.00817.17
7.2.120.0090.00316.74
7.2.110.0060.00617.13
7.2.100.0080.00417.06
7.2.90.0000.01417.06
7.2.80.0030.00616.74
7.2.70.0030.01416.77
7.2.60.0060.00816.79
7.2.50.0040.00817.16
7.2.40.0070.00716.99
7.2.30.0030.01017.24
7.2.20.0100.00316.74
7.2.10.0000.01417.16
7.2.00.0030.01018.23
7.1.250.0040.00715.90
7.1.200.0070.00715.77
7.1.100.0040.00818.13
7.1.70.0000.00716.88
7.1.60.0130.01035.21
7.1.50.0170.00734.87
7.1.40.0200.01334.69
7.1.30.0170.01034.55
7.1.20.0170.01034.80
7.1.10.0000.01016.63
7.1.00.0070.00716.78
7.0.200.0000.01016.57
7.0.190.0000.01016.86
7.0.180.0030.01316.26
7.0.170.0070.00716.18
7.0.160.0070.00316.19
7.0.150.0030.00716.29
7.0.140.0030.00716.41
7.0.130.0030.00716.49
7.0.120.0000.01316.49
7.0.110.0000.01016.53
7.0.100.0000.01016.51
7.0.90.0030.00716.40
7.0.80.0030.00716.37
7.0.70.0030.01016.14
7.0.60.0070.00316.30
7.0.50.0070.00316.48
7.0.40.0070.00316.43
7.0.30.0030.00716.54
7.0.20.0030.01016.23
7.0.10.0000.01016.39
7.0.00.0030.00716.51

preferences:
37.01 ms | 401 KiB | 5 Q