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']));

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.0000.01818.43
8.3.50.0110.00416.27
8.3.40.0000.01518.55
8.3.30.0120.00618.77
8.3.20.0000.01519.01
8.3.10.0040.00421.77
8.3.00.0030.00520.64
8.2.180.0140.00718.54
8.2.170.0110.00422.96
8.2.160.0090.00622.00
8.2.150.0050.00324.18
8.2.140.0000.00824.66
8.2.130.0040.00422.26
8.2.120.0050.00326.35
8.2.110.0080.00320.32
8.2.100.0000.01217.84
8.2.90.0050.00319.01
8.2.80.0050.00317.97
8.2.70.0080.00017.63
8.2.60.0000.00818.05
8.2.50.0050.00518.10
8.2.40.0000.00922.04
8.2.30.0020.00519.44
8.2.20.0000.00818.23
8.2.10.0060.00318.10
8.2.00.0040.00418.08
8.1.280.0070.00725.92
8.1.270.0030.00623.83
8.1.260.0040.00426.35
8.1.250.0030.00528.09
8.1.240.0060.00322.62
8.1.230.0040.00819.20
8.1.220.0050.00317.78
8.1.210.0000.00818.77
8.1.200.0060.00317.35
8.1.190.0000.00817.23
8.1.180.0090.00018.10
8.1.170.0030.00518.64
8.1.160.0050.00319.05
8.1.150.0040.00418.85
8.1.140.0060.00319.62
8.1.130.0030.00318.93
8.1.120.0040.00417.58
8.1.110.0050.00317.45
8.1.100.0000.00717.53
8.1.90.0060.00517.49
8.1.80.0000.00717.40
8.1.70.0030.00317.57
8.1.60.0030.00517.69
8.1.50.0040.00417.63
8.1.40.0030.00517.69
8.1.30.0090.00017.76
8.1.20.0050.00317.72
8.1.10.0020.00517.68
8.1.00.0050.00317.63
8.0.300.0000.00718.77
8.0.290.0040.00417.00
8.0.280.0000.00718.46
8.0.270.0000.00817.25
8.0.260.0030.00316.89
8.0.250.0080.00017.00
8.0.240.0000.01017.05
8.0.230.0040.00417.04
8.0.220.0070.00017.03
8.0.210.0040.00416.87
8.0.200.0000.00617.05
8.0.190.0000.00817.07
8.0.180.0040.00416.95
8.0.170.0040.00417.05
8.0.160.0000.00817.04
8.0.150.0040.00416.98
8.0.140.0040.00416.98
8.0.130.0000.00613.46
8.0.120.0050.00217.00
8.0.110.0030.00517.07
8.0.100.0040.00417.06
8.0.90.0000.00817.02
8.0.80.0060.01216.96
8.0.70.0000.00717.00
8.0.60.0050.00317.04
8.0.50.0040.00417.04
8.0.30.0050.01217.09
8.0.20.0110.00917.40
8.0.10.0040.00416.89
8.0.00.0130.00616.87
7.4.330.0000.00615.55
7.4.320.0040.00416.62
7.4.300.0030.00316.67
7.4.290.0030.00516.63
7.4.280.0030.00516.47
7.4.270.0030.00316.70
7.4.260.0060.00013.38
7.4.250.0030.00616.64
7.4.240.0000.00816.54
7.4.230.0000.00716.39
7.4.220.0000.01816.61
7.4.210.0100.00816.59
7.4.200.0040.00416.76
7.4.160.0110.00516.51
7.4.150.0110.00717.40
7.4.140.0100.00817.86
7.4.130.0130.00716.60
7.4.120.0070.01216.56
7.4.110.0160.00016.67
7.4.100.0090.00916.50
7.4.90.0080.00816.70
7.4.80.0140.00319.39
7.4.70.0060.00916.40
7.4.60.0100.00716.45
7.4.50.0070.00316.59
7.4.40.0090.00816.40
7.4.30.0120.01216.48
7.4.00.0060.00915.13
7.3.330.0030.00313.41
7.3.320.0050.00013.43
7.3.310.0040.00416.44
7.3.300.0000.00616.24
7.3.290.0070.00016.32
7.3.280.0060.01016.42
7.3.270.0100.00617.40
7.3.260.0170.00516.59
7.3.250.0160.00516.53
7.3.240.0140.00616.48
7.3.230.0080.00816.63
7.3.210.0150.00616.55
7.3.200.0090.01216.71
7.3.190.0030.01316.38
7.3.180.0140.00316.66
7.3.170.0130.01016.38
7.3.160.0060.01016.40
7.2.330.0090.00916.80
7.2.320.0140.00316.91
7.2.310.0060.01016.88
7.2.300.0120.00916.72
7.2.290.0140.00316.74
7.2.60.0000.01317.01
7.2.00.0000.00919.47
7.1.200.0030.01015.62
7.1.100.0030.01018.30
7.1.70.0040.00417.28
7.1.60.0970.00733.45
7.1.50.0800.01333.07
7.1.40.0900.01732.66
7.1.30.1070.01032.97
7.1.20.0870.00732.90
7.1.10.0570.01014.81
7.1.00.0600.01014.78
7.0.200.0730.01015.13
7.0.190.0730.00714.83
7.0.180.0030.00716.34
7.0.170.0770.00714.43
7.0.160.0630.01314.53
7.0.150.0530.01314.53
7.0.140.0670.00714.50
7.0.130.0030.01016.62
7.0.120.0030.01016.44
7.0.110.1400.00716.29
7.0.100.0770.00714.69
7.0.90.0730.00014.37
7.0.80.0630.00714.59
7.0.70.0630.01314.68
7.0.60.0800.00714.54
7.0.50.0700.00314.71
7.0.40.0630.00314.77
7.0.30.0030.01016.30
7.0.20.0070.00316.23
7.0.10.0030.00716.51
7.0.00.0000.01316.47

preferences:
43.2 ms | 401 KiB | 5 Q