3v4l.org

run code in 300+ PHP versions simultaneously
<?php final class IntFilter { public static function check(int $value, array $options = array()) { return $value; } } final class StringFilter { public static function check(string $value, array $options = array()) { // Trim if (false !== ($options['trim'] ?? true)) { $value = trim($value); } $length = mb_strlen($value, '8bit'); // Empty if (false === ($options['empty'] ?? true)) { if (0 === $length) { throw new LengthException('chaine vide !'); } } // Min & max length if (isset($options['max'])) { $maxLength = IntFilter::check($options['max'], ['min' => 1]); if ($length > $maxLength) { throw new LengthException('trop long !'); } } if (isset($options['min'])) { $minLength = IntFilter::check($options['min'], ['min' => 1]); if ($length < $minLength) { throw new LengthException('trop court !'); } } if (isset($options['startsWith'])) { $needle = StringFilter::check($options['startsWith']); if (false === self::startsWith($value, $needle)) { throw new InvalidArgumentException('mauvais début !'); } } if (isset($options['endsWith'])) { $needle = StringFilter::check($options['endsWith']); if (false === self::endsWith($value, $needle)) { throw new InvalidArgumentException('mauvaise fin !'); } } 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(' test ', ['endsWith' => 'st']));

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.0170.00318.31
8.3.50.0140.00016.26
8.3.40.0120.00418.89
8.3.30.0120.00818.84
8.3.20.0000.01019.10
8.3.10.0080.00023.52
8.3.00.0050.00320.94
8.2.180.0140.00718.54
8.2.170.0000.01522.96
8.2.160.0100.00322.11
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0060.00320.35
8.2.120.0050.00026.35
8.2.110.0100.00022.11
8.2.100.0060.00617.78
8.2.90.0080.00019.17
8.2.80.0030.00617.97
8.2.70.0060.00317.50
8.2.60.0050.00318.05
8.2.50.0030.00618.16
8.2.40.0000.00822.06
8.2.30.0050.00219.23
8.2.20.0070.00018.08
8.2.10.0030.00618.09
8.2.00.0000.00718.08
8.1.280.0150.00325.92
8.1.270.0050.00323.90
8.1.260.0000.00826.35
8.1.250.0040.00428.09
8.1.240.0040.00423.79
8.1.230.0090.00317.83
8.1.220.0000.00917.74
8.1.210.0000.00918.77
8.1.200.0030.00617.35
8.1.190.0040.00417.10
8.1.180.0000.00918.10
8.1.170.0050.00318.57
8.1.160.0040.00419.10
8.1.150.0040.00420.64
8.1.140.0000.00919.43
8.1.130.0050.00318.78
8.1.120.0030.00517.38
8.1.110.0030.00617.45
8.1.100.0050.00317.45
8.1.90.0030.00517.46
8.1.80.0000.00817.32
8.1.70.0000.00817.44
8.1.60.0050.00317.73
8.1.50.0040.00417.63
8.1.40.0040.00417.70
8.1.30.0040.00417.79
8.1.20.0090.00017.76
8.1.10.0070.00017.70
8.1.00.0060.00317.60
8.0.300.0000.00918.77
8.0.290.0070.00017.00
8.0.280.0000.00818.47
8.0.270.0040.00416.89
8.0.260.0070.00016.84
8.0.250.0030.00317.07
8.0.240.0040.00417.04
8.0.230.0050.00216.93
8.0.220.0030.00316.81
8.0.210.0030.00816.87
8.0.200.0050.00216.95
8.0.190.0080.00016.89
8.0.180.0030.00616.88
8.0.170.0040.00416.86
8.0.160.0070.00016.80
8.0.150.0030.00316.90
8.0.140.0030.00616.91
8.0.130.0060.00313.43
8.0.120.0020.00516.94
8.0.110.0040.00416.83
8.0.100.0000.00716.89
8.0.90.0040.00416.94
8.0.80.0070.01016.94
8.0.70.0000.00716.73
8.0.60.0040.00416.97
8.0.50.0040.00416.84
8.0.30.0120.00717.31
8.0.20.0110.00817.40
8.0.10.0000.00716.84
8.0.00.0120.00616.66
7.4.330.0060.00015.55
7.4.320.0060.00016.56
7.4.300.0030.00316.66
7.4.290.0030.00516.64
7.4.280.0040.00416.45
7.4.270.0050.00316.70
7.4.260.0000.00813.28
7.4.250.0070.00016.63
7.4.240.0000.00816.62
7.4.230.0030.00516.65
7.4.220.0420.00716.52
7.4.210.0140.00016.75
7.4.200.0000.00716.73
7.4.160.0070.01016.49
7.4.150.0110.00617.40
7.4.140.0070.01317.86
7.4.130.0100.01016.47
7.4.120.0110.00816.53
7.4.110.0130.00716.50
7.4.100.0060.01016.52
7.4.90.0070.01016.63
7.4.80.0120.01219.39
7.4.70.0130.00516.61
7.4.60.0100.00616.44
7.4.50.0040.00816.33
7.4.40.0100.01016.53
7.4.30.0120.00916.70
7.4.00.0110.00714.73
7.3.330.0030.00313.18
7.3.320.0050.00013.36
7.3.310.0000.00716.44
7.3.300.0060.00016.40
7.3.290.0060.01116.39
7.3.280.0090.00816.38
7.3.270.0060.01217.40
7.3.260.0080.00916.43
7.3.250.0110.00916.50
7.3.240.0080.00916.70
7.3.230.0170.00316.64
7.3.210.0070.01016.44
7.3.200.0130.00916.71
7.3.190.0140.00916.28
7.3.180.0070.01016.59
7.3.170.0130.00316.36
7.3.160.0090.01216.48
7.2.330.0090.00916.72
7.2.320.0030.01316.62
7.2.310.0040.01416.66
7.2.300.0130.01016.57
7.2.290.0040.01816.32
7.2.60.0090.00616.96
7.2.00.0030.01319.43
7.1.200.0040.01115.70
7.1.100.0080.00318.31
7.1.70.0000.00917.12
7.1.60.0870.01033.28
7.1.50.0730.02033.18
7.1.40.0170.01032.80
7.1.30.0300.01332.69
7.1.20.1170.00732.90
7.1.10.0670.01314.94
7.1.00.0070.01715.06
7.0.200.0770.01014.95
7.0.190.0930.00714.87
7.0.180.0030.00714.23
7.0.170.0230.01014.60
7.0.160.0430.00714.38
7.0.150.0930.00714.38
7.0.140.0770.00714.46
7.0.130.1030.00014.58
7.0.120.0270.01315.04
7.0.110.0070.00714.50
7.0.100.0230.01314.54
7.0.90.0800.01014.44
7.0.80.0870.01314.65
7.0.70.0070.00714.48
7.0.60.0570.01714.28
7.0.50.0870.00314.75
7.0.40.0800.01014.78
7.0.30.0000.01014.64
7.0.20.0330.01314.47
7.0.10.0030.00714.55
7.0.00.0700.01014.77

preferences:
60.45 ms | 401 KiB | 5 Q