3v4l.org

run code in 300+ PHP versions simultaneously
<?php function benchmark(string $name, callable $callback) { $string = ')(§"!$&&))§/$"=$/%$%$!§%%"§=)$(&§"&$/%!(%(!$(%$!=!%==!§(%§$8234@#$ABCFG3478&* hello'; $time = microtime(true); for ($i = 0; $i < 100_000; ++$i) { $callback($string); } $time = microtime(true) - $time; echo number_format($time, 6), 's: ', $name, ' (result: ', $callback($string), ")\n"; } benchmark('preg', function (string $string) { $firstLetter = null; if (preg_match('/[a-z0-9]/i', $string, $match)) { $firstLetter = $match[0]; } return $firstLetter; }); benchmark('ctype_alnum', function (string $string) { $length = strlen($string); $firstLetter = null; for ($i = 0; $i < $length; ++$i) { if (ctype_alnum($string[$i])) { $firstLetter = $string[$i]; break; } } return $firstLetter; }); benchmark('strcspn', function (string $string) { return $string[strcspn($string, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")] ?? null; });

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)
7.4.80.0100.89416.49
7.4.70.0160.94916.66
7.4.60.0130.91216.67
7.4.50.0201.08616.41
7.4.40.0160.84916.70
7.4.30.0160.92416.59
7.4.20.0240.95416.55
7.4.10.0160.90016.86
7.4.00.0120.92716.93
7.3.200.0120.00916.27
7.3.190.0040.01316.21
7.3.180.0140.00316.28
7.3.170.0090.00916.05
7.3.160.0070.01116.05
7.3.150.0160.01116.09
7.3.140.0100.00715.98
7.3.130.0140.00716.17
7.3.120.0140.00316.28
7.3.110.0150.00716.34
7.3.100.0070.01016.12
7.3.90.0060.01016.27
7.3.80.0160.00716.09
7.3.70.0100.01316.17
7.3.60.0100.00716.22
7.3.50.0130.00316.02
7.3.40.0100.00716.20
7.3.30.0100.00616.11
7.3.20.0040.01516.18
7.3.10.0070.01116.23
7.3.00.0100.01316.25
7.2.320.0070.01716.34
7.2.310.0100.01016.32
7.2.300.0090.01216.10
7.2.290.0130.00916.37
7.2.280.0170.00716.48
7.2.270.0090.01616.51
7.2.260.0140.00316.37
7.2.250.0070.01616.29
7.2.240.0100.00716.27
7.2.230.0090.00916.33
7.2.220.0100.00716.48
7.2.210.0150.00916.41
7.2.200.0130.00616.14
7.2.190.0120.01216.23
7.2.180.0090.00916.23
7.2.170.0040.01816.44
7.2.160.0060.01216.43
7.2.150.0090.00916.41
7.2.140.0120.00916.27
7.2.130.0070.01716.54
7.2.120.0090.00916.51
7.2.110.0120.00616.41
7.2.100.0060.01216.55
7.2.90.0130.00616.45
7.2.80.0250.00916.39
7.2.70.0400.00416.36
7.2.60.0080.01116.13
7.2.50.0160.00716.42
7.2.40.0100.01316.34
7.2.30.0120.00616.54
7.2.20.0000.02016.48
7.2.10.0100.01316.44
7.2.00.0060.01216.38

preferences:
50.35 ms | 738 KiB | 5 Q