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($length, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } var_dump(random_str(5)); var_dump(random_str(5, 'abcdefghijklmnopqrstuvwxyz'));

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.3.10.0040.01116.84
7.3.00.0040.00816.70
7.2.130.0000.01517.00
7.2.120.0110.00316.93
7.2.110.0030.00717.06
7.2.100.0060.00616.91
7.2.90.0090.00017.01
7.2.80.0030.00917.00
7.2.70.0100.00616.94
7.2.60.0450.00716.10
7.2.50.0030.01017.04
7.2.40.0070.00716.96
7.2.30.0060.00916.95
7.2.20.0080.00016.95
7.2.10.0030.00917.05
7.2.00.0100.01018.06
7.1.250.0000.01415.97
7.1.100.0080.00317.74
7.1.70.0000.00817.00
7.1.60.0080.00617.31
7.1.50.0060.00617.19
7.1.40.0070.01616.64
7.1.30.0030.01616.76
7.1.20.0000.01916.82
7.1.10.0030.01316.64
7.1.00.0070.00016.88
7.0.200.0030.00316.68
7.0.190.0000.00716.83
7.0.180.0060.01016.64
7.0.170.0000.00816.64
7.0.160.0070.01016.64
7.0.150.0040.00716.64
7.0.140.0030.00816.64
7.0.130.0080.00016.85
7.0.120.0100.00016.64
7.0.110.0000.01216.64
7.0.100.0000.00716.64
7.0.90.0000.00916.64
7.0.80.0100.00716.64
7.0.70.0000.00816.64
7.0.60.0030.00716.64
7.0.50.0060.00316.64
7.0.40.0000.00816.64
7.0.30.0030.01316.64
7.0.20.0060.00316.64
7.0.10.0000.00816.64
7.0.00.0030.00516.64

preferences:
36.23 ms | 400 KiB | 5 Q