3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isPalindrome(string &$str): bool { if ($str === '') { return false; // an empty string is not a palindrome } if (strlen($str) === 1) { return true; // odd length string is a palindrome, do not recurse } if ($str[0] !== $str[strlen($str) - 1]) { return false; // outermost characters are not identical, halt processing } $str = substr($str, 1, -1); // shed outermost charcters if ($str === '') { return true; // even length string is a palindrome, do not recurse } return (__FUNCTION__)($str); // traverse deeper and bubble outcome to top level } function sanitizePalindrome(&$str) { return preg_replace('/[^a-z]+/', '', strtolower($str)); } $tests = [ '', 'radar', 'f', 'neveroddoreven', 'foo', 'palindrome', 'Red rum, sir, is murder' ]; foreach ($tests as $test) { $test = sanitizePalindrome($test); // this is optional printf("%20s : %s\n", $test, json_encode(isPalindrome($test))); }

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.4.120.0110.01120.56
8.4.110.0020.00624.31
8.4.100.0100.01118.10
8.4.90.0150.00519.72
8.4.80.0140.00618.00
8.4.70.0120.00918.08
8.4.60.0150.00617.85
8.4.50.0050.00617.78
8.4.40.0100.01018.03
8.4.30.0050.00319.00
8.4.20.0150.00417.98
8.4.10.0000.00819.43
8.3.250.0120.00817.20
8.3.240.0140.00516.77
8.3.230.0130.00616.69
8.3.220.0060.00417.10
8.3.210.0060.00516.65
8.3.200.0090.01016.36
8.3.190.0100.00916.77
8.3.180.0110.00818.54
8.3.170.0100.00720.86
8.3.160.0080.00017.11
8.3.150.0110.00717.36
8.3.140.0000.01917.04
8.3.130.0050.00318.41
8.3.120.0100.00019.03
8.3.110.0030.00616.59
8.3.100.0040.00424.06
8.3.90.0070.01126.77
8.3.80.0090.00017.97
8.3.70.0100.00718.56
8.3.60.0150.00318.51
8.3.50.0150.00616.57
8.3.40.0070.00721.73
8.3.30.0070.00721.88
8.3.20.0000.00925.66
8.3.10.0050.00325.66
8.3.00.0090.00925.66
8.2.290.0100.00620.27
8.2.280.0140.00618.51
8.2.270.0170.00317.12
8.2.260.0130.00318.55
8.2.250.0040.01116.91
8.2.240.0000.01817.04
8.2.230.0000.00820.94
8.2.220.0060.00337.54
8.2.210.0000.00826.77
8.2.200.0100.00017.00
8.2.190.0070.00718.50
8.2.180.0110.01116.75
8.2.170.0070.01419.10
8.2.160.0100.00322.96
8.2.150.0060.00325.66
8.2.140.0040.00425.66
8.2.130.0040.00425.66
8.2.120.0080.00025.66
8.2.110.0050.00325.66
8.2.100.0060.01225.66
8.2.90.0130.00625.66
8.2.80.0040.00425.66
8.2.70.0080.00025.66
8.2.60.0040.00425.66
8.2.50.0040.00425.66
8.2.40.0060.00325.66
8.2.30.0180.00025.66
8.2.20.0090.00925.66
8.2.10.0090.00025.66
8.2.00.0040.00425.66
8.1.330.0110.00816.93
8.1.320.0090.00916.53
8.1.310.0130.00616.71
8.1.300.0090.00018.23
8.1.290.0090.00330.84
8.1.280.0110.00725.92
8.1.270.0040.00425.66
8.1.260.0060.01325.66
8.1.250.0120.00625.66
8.1.240.0090.00025.66
8.1.230.0040.00425.66
8.1.220.0080.00025.66
8.1.210.0000.00825.66
8.1.200.0040.00425.66
8.1.190.0090.00925.66
8.1.180.0030.00625.66
8.1.170.0120.00825.66
8.1.160.0120.00625.66
8.1.150.0150.00325.66
8.1.140.0060.00325.66
8.1.130.0040.00425.66
8.1.120.0040.00425.66
8.1.110.0040.00425.66
8.1.100.0110.00425.66
8.1.90.0040.00425.66
8.1.80.0040.00425.66
8.1.70.0060.01025.66
8.1.60.0070.00725.66
8.1.50.0040.00425.66
8.1.40.0000.00825.66
8.1.30.0030.00625.66
8.1.20.0080.00025.66
8.1.10.0030.00525.66
8.1.00.0030.00625.66

preferences:
46.34 ms | 403 KiB | 5 Q