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 < 500_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.0130.38616.88
7.4.70.0100.38416.59
7.4.60.0100.39216.75
7.4.50.0030.39716.75
7.4.40.0070.40616.78
7.4.30.0130.36916.73
7.4.20.0070.45616.46
7.4.10.0130.38716.92
7.4.00.0030.38716.96
7.3.200.0030.01416.02
7.3.190.0080.00816.40
7.3.180.0070.01016.20
7.3.170.0040.01116.11
7.3.160.0040.01216.29
7.3.150.0040.01116.29
7.3.140.0040.01116.13
7.3.130.0000.01616.37
7.3.120.0030.01316.33
7.3.110.0060.01015.93
7.3.100.0100.00616.46
7.3.90.0030.01316.21
7.3.80.0110.00716.30
7.3.70.0090.00616.22
7.3.60.0140.00316.22
7.3.50.0090.00816.04
7.3.40.0030.01416.23
7.3.30.0060.01516.18
7.3.20.0100.01016.17
7.3.10.0060.00916.43
7.3.00.0150.00916.06
7.2.320.0120.00616.17
7.2.310.0120.00416.42
7.2.300.0090.01316.23
7.2.290.0060.00916.47
7.2.280.0090.00616.50
7.2.270.0110.01116.15
7.2.260.0090.00916.40
7.2.250.0060.01316.35
7.2.240.0030.01316.58
7.2.230.0080.00816.51
7.2.220.0120.00616.16
7.2.210.0060.00916.32
7.2.200.0030.01316.47
7.2.190.0030.01716.37
7.2.180.0060.01216.21
7.2.170.0060.01616.18
7.2.160.0130.00716.40
7.2.150.0150.00616.39
7.2.140.0070.01016.47
7.2.130.0060.01816.16
7.2.120.0090.01516.43
7.2.110.0070.01116.18
7.2.100.0070.01116.47
7.2.90.0090.00916.32
7.2.80.0170.00716.38
7.2.70.0140.00316.50
7.2.60.0070.01116.34
7.2.50.0090.00916.45
7.2.40.0070.01316.47
7.2.30.0120.01116.46
7.2.20.0090.01516.34
7.2.10.0120.01216.30
7.2.00.0070.01716.57

preferences:
51.03 ms | 738 KiB | 5 Q