3v4l.org

run code in 300+ PHP versions simultaneously
<?php function isLongerThanCT(string $input, int $targetLength): bool { $amount = PHP_INT_SIZE === 8 ? 63 : 31; $len = strlen($input); // use mb_strlen($input, '8bit'); on older PHP $res = (($targetLength - $len) >> $amount) & 1; /* * It's worth taking a moment to explain what the hell the line above is doing. * * ($targetLength - $len) will return a negative value if $targetLength is larger than $len. * * By two's complement, negative values when shifted 31 or 63 places to the right will have a lower * bit set. We then use a bit mask of `1` and the bitwise `&` operator on the result of the bitshift. * * End result? It's the same as if we did the following, except constant-time: * $res = (int) ($len > $targetLength); */ return (bool) ($res); } $long = str_repeat('A', 72); var_dump( isLongerThanCT($long, 71), isLongerThanCT($long, 72), isLongerThanCT($long, 73) );

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.20.0120.00921.31
8.4.10.0160.00619.72
8.3.150.0180.00017.09
8.3.140.0380.00816.43
8.3.130.0300.01116.25
8.3.120.0320.00816.55
8.3.110.0330.00716.82
8.3.100.0440.00316.27
8.3.90.0330.01316.63
8.3.80.0270.00316.45
8.3.70.0220.01116.33
8.3.60.0300.01516.43
8.3.50.0380.00716.77
8.3.40.0390.00017.40
8.3.30.0300.00617.43
8.3.20.0320.00417.39
8.3.10.0300.00617.54
8.3.00.0170.00317.53
8.2.270.0110.00716.77
8.2.260.0240.00816.76
8.2.250.0170.01716.55
8.2.240.0260.00616.50
8.2.230.0220.01316.53
8.2.220.0230.01316.76
8.2.210.0320.00816.00
8.2.200.0180.01816.82
8.2.190.0240.01516.43
8.2.180.0210.01216.64
8.2.170.0260.01617.95
8.2.160.0270.01017.54
8.2.150.0220.01917.55
8.2.140.0380.00317.46
8.2.130.0310.00617.51
8.2.120.0330.00017.34
8.2.110.0240.00317.67
8.2.100.0190.00017.57
8.2.90.0180.00317.44
8.2.80.0150.00417.51
8.2.70.0340.00617.64
8.2.60.0350.00617.29
8.2.50.0320.00817.52
8.2.40.0280.00617.61
8.2.30.0270.00317.57
8.2.20.0320.00617.45
8.2.10.0230.01317.35
8.2.00.0240.01217.48

preferences:
36.76 ms | 403 KiB | 5 Q