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'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r', 'endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r', 'endsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z', 'endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z', 'endsWith' => 'y']));

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.0120.00918.43
8.3.50.0120.00316.25
8.3.40.0070.00718.70
8.3.30.0110.00418.67
8.3.20.0090.00018.98
8.3.10.0050.00321.79
8.3.00.0080.00020.73
8.2.180.0110.01118.66
8.2.170.0040.01122.96
8.2.160.0140.00022.12
8.2.150.0000.01125.66
8.2.140.0040.00424.66
8.2.130.0000.00820.45
8.2.120.0040.00426.35
8.2.110.0030.00722.33
8.2.100.0090.00317.78
8.2.90.0040.00419.17
8.2.80.0050.00817.97
8.2.70.0060.00317.75
8.2.60.0050.00317.93
8.2.50.0000.00818.10
8.2.40.0030.00622.30
8.2.30.0040.00419.29
8.2.20.0050.00318.23
8.2.10.0040.00418.20
8.2.00.0000.00718.17
8.1.280.0140.00325.92
8.1.270.0050.00523.88
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0070.00322.66
8.1.230.0040.00817.89
8.1.220.0050.00317.77
8.1.210.0040.00418.77
8.1.200.0040.00417.35
8.1.190.0030.00617.22
8.1.180.0030.00618.10
8.1.170.0090.00018.62
8.1.160.0000.00819.03
8.1.150.0050.00218.81
8.1.140.0030.00719.65
8.1.130.0050.00218.85
8.1.120.0040.00417.51
8.1.110.0040.00417.52
8.1.100.0000.00817.39
8.1.90.0000.00917.48
8.1.80.0080.00017.54
8.1.70.0030.00317.41
8.1.60.0030.00617.58
8.1.50.0040.00417.52
8.1.40.0040.00417.52
8.1.30.0040.00417.71
8.1.20.0040.00417.75
8.1.10.0040.00417.61
8.1.00.0050.00317.51
8.0.300.0040.00418.77
8.0.290.0000.00816.88
8.0.280.0000.00718.55
8.0.270.0000.00717.36
8.0.260.0030.00316.93
8.0.250.0030.00317.09
8.0.240.0030.00617.05
8.0.230.0000.00817.10
8.0.220.0030.00417.02
8.0.210.0070.00017.04
8.0.200.0070.00017.08
8.0.190.0060.00316.92
8.0.180.0040.00717.06
8.0.170.0040.00416.97
8.0.160.0040.00417.02
8.0.150.0030.00516.98
8.0.140.0000.00716.95
8.0.130.0030.00313.43
8.0.120.0050.00316.94
8.0.110.0050.00317.03
8.0.100.0040.00417.06
8.0.90.0070.00017.12
8.0.80.0060.01017.02
8.0.70.0020.00516.89
8.0.60.0000.00817.00
8.0.50.0050.00217.02
8.0.30.0100.00817.09
8.0.20.0150.00717.40
8.0.10.0040.00416.90
8.0.00.0110.00617.07
7.4.330.0060.00015.55
7.4.320.0030.00316.44
7.4.300.0060.00016.64
7.4.290.0030.00616.60
7.4.280.0040.00416.54
7.4.270.0000.00716.69
7.4.260.0050.00013.36
7.4.250.0030.00316.56
7.4.240.0080.00016.57
7.4.230.0000.00816.73
7.4.220.0090.01516.64
7.4.210.0080.00716.50
7.4.200.0030.00316.74
7.4.160.0090.00716.42
7.4.150.0200.00617.40
7.4.140.0070.01017.86
7.4.130.0130.00616.59
7.4.120.0110.01216.59
7.4.110.0030.01316.58
7.4.100.0040.01316.43
7.4.90.0080.00816.57
7.4.80.0040.01319.39
7.4.70.0090.01216.37
7.4.60.0100.00716.55
7.4.50.0070.00716.44
7.4.40.0100.00716.50
7.4.30.0130.00916.66
7.4.00.0070.00714.63
7.3.330.0030.00313.22
7.3.320.0050.00013.47
7.3.310.0070.00016.39
7.3.300.0070.00016.41
7.3.290.0030.00316.36
7.3.280.0070.01016.39
7.3.270.0110.00617.40
7.3.260.0090.01216.62
7.3.250.0100.00916.49
7.3.240.0090.00816.38
7.3.230.0150.00316.34
7.3.210.0070.01516.46
7.3.200.0080.00816.56
7.3.190.0080.01216.43
7.3.180.0070.01016.51
7.3.170.0090.00916.38
7.3.160.0030.01316.50
7.2.330.0070.01316.54
7.2.320.0090.00916.82
7.2.310.0080.00816.94
7.2.300.0140.00616.77
7.2.290.0090.01416.82
7.2.60.0260.00317.07
7.2.50.0000.00816.91
7.2.00.0030.00619.39
7.1.200.0090.00315.89
7.1.100.0060.00617.95
7.1.70.0000.00717.24
7.1.60.0130.01034.97
7.1.50.0070.01734.85
7.1.40.0130.01034.45
7.1.30.0170.00734.67
7.1.20.0170.01034.52
7.1.10.0030.01016.43
7.1.00.0030.00716.82
7.0.200.0000.01016.71
7.0.190.0000.01016.89
7.0.180.0070.00316.31
7.0.170.0030.00716.24
7.0.160.0030.00716.34
7.0.150.0070.00716.24
7.0.140.0100.00716.52
7.0.130.0030.01316.47
7.0.120.0030.00716.79
7.0.110.0100.00316.53
7.0.100.0070.00316.25
7.0.90.0030.01016.51
7.0.80.0030.01316.64
7.0.70.0030.01314.66
7.0.60.1130.00314.45
7.0.50.1000.01314.52
7.0.40.0930.01014.66
7.0.30.0970.01014.83
7.0.20.0770.00714.91
7.0.10.0670.01314.63
7.0.00.0870.01014.86

preferences:
55.18 ms | 401 KiB | 5 Q