3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * For PHP 7, random_int is a PHP core function * For PHP 5.x, depends on https://github.com/paragonie/random_compat * * @param int $length How many characters do we want? * @param string $keyspace A string of all possible characters * to select from * @return string */ function random_str( int $length = 64, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' ): string { if ($length < 1) { throw new \RangeException("Length must be a positive integer"); } $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } $a = random_str(4, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); $b = random_str(10, '123456789'); $c = random_str(); var_dump($a, $b, $c);
based on f7tVG

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.120.0130.00716.25
7.4.110.0120.00916.47
7.4.100.0120.00916.35
7.4.90.0110.01116.17
7.4.80.0140.00916.32
7.4.70.0150.00916.29
7.4.60.0140.00916.41
7.4.50.0140.00716.40
7.4.40.0120.01016.32
7.4.30.0070.01216.42
7.4.20.0130.01016.22
7.4.10.0120.00916.41
7.4.00.0120.01016.47
7.3.240.0120.01016.32
7.3.230.0090.01016.33
7.3.220.0130.01016.37
7.3.210.0130.00816.53
7.3.200.0130.01016.39
7.3.190.0160.00916.41
7.3.180.0150.00916.35
7.3.170.0120.01016.27
7.3.160.0130.00916.40
7.3.150.0120.00816.43
7.3.140.0090.01116.36
7.3.130.0110.00916.36
7.3.120.0120.01016.33
7.3.110.0150.00616.46
7.3.100.0110.01116.33
7.3.90.0110.01116.40
7.3.80.0140.01016.46
7.3.70.0130.01016.31
7.3.60.0130.00916.33
7.3.50.0140.01016.29
7.3.40.0140.00816.25
7.3.30.0110.01116.33
7.3.20.0150.00816.43
7.3.10.0120.01116.36
7.3.00.0160.00916.41
7.2.340.0130.00916.61
7.2.330.0110.01116.48
7.2.320.0110.00916.51
7.2.310.0140.01016.66
7.2.300.0110.01216.48
7.2.290.0110.01216.45
7.2.280.0160.00516.59
7.2.270.0130.00916.55
7.2.260.0150.00816.55
7.2.250.0150.00816.50
7.2.240.0140.00916.56
7.2.230.0110.01116.46
7.2.220.0120.01216.54
7.2.210.0110.01316.49
7.2.200.0150.00916.51
7.2.190.0120.01016.53
7.2.180.0110.01216.47
7.2.170.0160.00916.50
7.2.160.0120.00916.59
7.2.150.0130.01016.59
7.2.140.0150.00916.67
7.2.130.0190.01016.60
7.2.120.0120.01016.51
7.2.110.0150.00716.56
7.2.100.0100.01416.63
7.2.90.0160.00816.54
7.2.80.0140.01116.58
7.2.70.0130.00916.66
7.2.60.0170.00716.49
7.2.50.0140.00916.53
7.2.40.0110.01116.63
7.2.30.0140.00916.55
7.2.20.0150.00716.62
7.2.10.0130.00816.47
7.2.00.0600.01016.43