3v4l.org

run code in 500+ PHP versions simultaneously
<?php /** * Напишите реализацию для ф-ии strstr: * function strstr(string $haystack, string $needle) * нельзя использовать встроенные ф-ии php: substr, strtok, ... * (*) это более удачная реализация, работает за О(n) */ /** * Find substring starting in string, starting from some symbol(s) * @param string $haystack * @param string $needle * @return string */ function my_strstr2(string $haystack, string $needle): string { $isFound = false; $lenHaystack = strlen($haystack); $lenNeedle = strlen($needle); for($i = 0, $j = 0, $cnt = 0; $i < $lenHaystack, $j < $lenNeedle; $i++) { if($haystack[$i + $j] == $needle[$j]) { $j++; } else { $j = 0; } if($j >= strlen($lenNeedle)) { $isFound = true; break; } } return ($isFound ? substr($haystack, $i) : ''); } var_dump(my_strstr2('asdfghend', 'fg')); // 'fghend';

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.5.70.0090.00816.89
8.5.60.0080.01216.98
8.5.50.0120.00516.73
8.5.30.0110.00619.50
8.5.20.0110.00617.73
8.5.10.0130.01016.62
8.5.00.0110.01220.08
8.4.220.0140.01022.18
8.4.210.0120.00919.41
8.4.180.0110.01023.88
8.4.170.0160.00823.68
8.4.160.0130.00923.88
8.4.150.0070.00516.76
8.4.140.0180.01017.66
8.4.130.0060.00417.57
8.4.120.0100.00720.55
8.4.110.0130.00722.66
8.4.100.0120.00817.73
8.4.90.0110.01022.50
8.4.80.0050.00519.63
8.4.70.0050.00318.11
8.4.60.0110.00818.82
8.4.50.0150.00520.30
8.4.40.0210.00017.79
8.4.30.0080.00020.57
8.4.20.0100.00722.23
8.4.10.0090.00023.89
8.3.310.0130.00818.55
8.3.300.0110.01019.18
8.3.290.0160.01420.76
8.3.280.0100.01018.29
8.3.270.0080.00116.67
8.3.260.0090.00416.18
8.3.250.0140.00421.02
8.3.240.0100.00916.60
8.3.230.0100.00916.52
8.3.220.0050.00318.84
8.3.210.0040.00316.56
8.3.200.0050.00416.65
8.3.190.0090.01017.07
8.3.180.0050.00916.85
8.3.170.0110.00417.04
8.3.160.0090.00918.54
8.3.150.0160.00316.40
8.3.140.0150.00420.91
8.3.130.0060.00918.61
8.3.120.0080.00019.01
8.3.110.0030.00620.94
8.3.100.0120.00624.06
8.3.90.0130.00326.77
8.3.80.0070.00418.56
8.3.70.0120.00316.75
8.3.60.0140.00418.30
8.3.50.0070.00716.49
8.3.40.0000.01422.08
8.3.30.0080.00619.04
8.3.20.0000.00824.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.300.0120.00818.02
8.2.290.0130.00720.82
8.2.280.0110.00818.41
8.2.270.0100.01017.37
8.2.260.0040.00416.74
8.2.250.0030.00618.33
8.2.240.0000.00917.07
8.2.230.0060.00322.58
8.2.220.0030.00637.54
8.2.210.0040.00426.77
8.2.200.0050.00516.50
8.2.190.0090.00616.88
8.2.180.0030.01616.63
8.2.170.0150.00418.88
8.2.160.0120.00322.96
8.2.150.0000.00825.66
8.2.140.0070.00024.66
8.2.130.0040.00426.16
8.2.120.0000.00819.89
8.2.110.0100.00619.30
8.2.100.0120.00017.72
8.2.90.0290.00618.58
8.2.80.0180.01218.52
8.2.70.0250.00618.30
8.2.60.0300.00018.45
8.2.50.0270.00318.63
8.2.40.0190.00818.64
8.2.30.0230.00318.50
8.2.20.0250.00418.69
8.2.10.0210.00718.63
8.2.00.0220.00918.73
8.1.340.0110.00917.67
8.1.330.0120.00721.99
8.1.320.0130.00716.33
8.1.310.0100.00318.11
8.1.300.0030.00617.95
8.1.290.0040.00430.84
8.1.280.0110.00425.92
8.1.270.0000.00824.66
8.1.260.0070.00026.35
8.1.250.0070.00028.09
8.1.240.0070.00323.83
8.1.230.0070.00420.93
8.1.220.0130.01618.44
8.1.210.0310.00318.42
8.1.200.0270.00518.31
8.1.190.0240.00318.21
8.1.180.0190.00818.32
8.1.170.0220.00618.43
8.1.160.0260.00018.53
8.1.150.0190.01018.39
8.1.140.0300.00418.41
8.1.130.0220.00718.49
8.1.120.0230.00418.31
8.1.110.0240.00418.61
8.1.100.0240.00818.48
8.1.90.0200.00818.58
8.1.80.0220.00518.51
8.1.70.0230.01018.53
8.1.60.0250.00318.69
8.1.50.0230.00318.46
8.1.40.0240.00318.53
8.1.30.0200.00818.55
8.1.20.0220.00618.57
8.1.10.0190.00818.57
8.1.00.0240.00418.42
8.0.300.0270.00017.77
8.0.290.0280.00017.73
8.0.280.0230.00317.75
8.0.270.0190.00817.58
8.0.260.0190.00917.99
8.0.250.0250.00217.61
8.0.240.0240.00318.02
8.0.230.0250.00417.86
8.0.220.0200.00817.64
8.0.210.0270.00417.56
8.0.200.0280.00317.84
8.0.190.0220.00617.91
8.0.180.0210.00717.72
8.0.170.0170.01017.50
8.0.160.0220.00617.89
8.0.150.0310.00317.57
8.0.140.0260.00317.86
8.0.130.0260.00017.52
8.0.120.0170.01217.86
8.0.110.0190.00517.88
8.0.100.0200.00317.94
8.0.90.0280.00017.75
8.0.80.0280.00317.37
8.0.70.0220.00317.42
8.0.60.0270.00017.75
8.0.50.0170.01017.88
8.0.30.0250.00317.75
8.0.20.0260.00317.80
8.0.10.0240.00317.71

preferences:
92.13 ms | 1123 KiB | 5 Q