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') { $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } var_dump(random_str(32)); var_dump(random_str(8, '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)
8.1.40.0070.00317.52
7.4.90.0370.00916.29
7.4.80.0190.01116.35
7.4.70.0280.00716.60
7.4.60.0250.01416.61
7.4.50.0200.01116.39
7.4.40.0190.01016.32
7.4.30.0160.01116.38
7.4.20.0160.01016.43
7.4.10.0140.01116.36
7.4.00.0120.00716.09
7.3.210.0380.00916.36
7.3.200.0180.00916.50
7.3.190.0210.01716.45
7.3.180.0270.01316.58
7.3.170.0190.01116.28
7.3.160.0190.01016.37
7.3.150.0170.01016.41
7.3.140.0180.00816.39
7.3.130.0190.00816.38
7.3.120.0160.01016.10
7.3.110.0140.01216.12
7.3.100.0140.00815.67
7.3.90.0140.00815.67
7.3.80.0120.01115.61
7.3.70.0110.00815.15
7.3.60.0100.00815.06
7.3.50.0120.00814.97
7.3.40.0110.00814.92
7.3.30.0100.00814.86
7.3.20.0530.00815.13
7.3.10.0570.00715.11
7.3.00.0530.00715.01
7.2.330.0250.01716.65
7.2.320.0260.01316.72
7.2.310.0280.01116.65
7.2.300.0270.00916.59
7.2.290.0170.01116.50
7.2.280.0180.00916.48
7.2.270.0170.01116.51
7.2.260.0170.01016.61
7.2.250.0180.01116.39
7.2.240.0180.00816.28
7.2.230.0140.01016.00
7.2.220.0130.01015.86
7.2.210.0110.01115.74
7.2.200.0110.00815.33
7.2.190.0100.00915.26
7.2.180.0090.00915.15
7.2.170.0090.00915.13
7.2.160.0090.00915.13
7.2.150.0500.00815.39
7.2.140.0510.00915.42
7.2.130.0520.00815.27
7.2.120.0690.00715.19
7.2.110.0580.00815.13
7.2.100.0540.00915.16
7.2.90.0500.00815.18
7.2.80.0510.00815.16
7.2.70.0490.00815.26
7.2.60.0480.00815.21
7.2.50.0490.00815.21
7.2.40.0450.00815.26
7.2.30.0480.00815.25
7.2.20.0480.00815.21
7.2.10.0460.00815.22
7.2.00.0460.00815.24
7.1.330.0230.00915.38
7.1.320.0210.00714.80
7.1.310.0190.00714.77
7.1.300.0160.00814.43
7.1.290.0150.00814.46
7.1.280.0180.00814.50
7.1.270.0320.00814.42
7.1.260.0290.00814.47
7.1.250.0570.00714.20
7.1.240.0620.00914.17
7.1.230.0580.00914.11
7.1.220.0600.00914.11
7.1.210.0570.00914.12
7.1.200.0570.00814.14
7.1.190.0510.00814.12
7.1.180.0540.00714.10
7.1.170.0530.00814.12
7.1.160.0480.00814.13
7.1.150.0470.00914.15
7.1.140.0500.00914.17
7.1.130.0460.00914.16
7.1.120.0510.00814.17
7.1.110.0460.00814.17
7.1.100.0500.00814.16
7.1.90.0450.00814.18
7.1.80.0480.00814.19
7.1.70.0430.00814.15
7.1.60.0500.00716.24
7.1.50.0470.00816.22
7.1.40.0420.00716.15
7.1.30.0470.00816.19
7.1.20.0450.00816.19
7.1.10.0420.00814.12
7.1.00.0400.00814.16
7.0.330.0590.00713.81
7.0.320.0590.00713.95
7.0.310.0500.00813.93
7.0.300.0470.00813.90
7.0.290.0460.00713.93
7.0.280.0420.00813.90
7.0.270.0460.00713.88
7.0.260.0400.00813.92
7.0.250.0470.00913.93
7.0.240.0410.00813.99
7.0.230.0390.00913.96
7.0.220.0410.00813.92
7.0.210.0380.00813.93
7.0.200.0430.00813.93
7.0.190.0390.00713.94
7.0.180.0360.00813.94
7.0.170.0350.00913.97
7.0.160.0360.00813.96
7.0.150.0340.00813.95
7.0.140.0330.00814.01
7.0.130.0320.00813.96
7.0.120.0380.00713.98
7.0.110.0400.00813.94
7.0.100.0370.00713.92
7.0.90.0340.00813.94
7.0.80.0300.00713.91
7.0.70.0350.00813.99
7.0.60.0340.00813.95
7.0.50.0300.00813.97
7.0.40.0320.00813.99
7.0.30.0300.00914.00
7.0.20.0340.00813.96
7.0.10.0300.00813.95
7.0.00.0290.00714.12
5.6.400.0140.00914.38
5.6.390.0130.01114.38
5.6.380.0130.00914.26
5.6.370.0130.01014.39
5.6.360.0150.00814.39
5.6.350.0140.00914.40
5.6.340.0150.00914.41
5.6.330.0140.01014.39
5.6.320.0140.00814.40
5.6.310.0130.00914.41
5.6.300.0150.00814.38
5.6.290.0140.00914.44
5.6.280.0140.00914.38
5.6.270.0140.00814.58
5.6.260.0140.00814.42
5.6.250.0140.00914.42
5.6.240.0140.00914.40
5.6.230.0140.00914.39
5.6.220.0130.00914.41
5.6.210.0130.01014.38
5.6.200.0140.00914.35
5.6.190.0130.01114.38
5.6.180.0130.01014.41
5.6.170.0120.01014.37
5.6.160.0130.00914.37
5.6.150.0140.00714.38
5.6.140.0140.00914.38
5.6.130.0130.00914.41
5.6.120.0130.00814.37
5.6.110.0130.00814.35
5.6.100.0130.00814.37
5.6.90.0130.00914.35
5.6.80.0120.00914.29
5.6.70.0130.00914.30
5.6.60.0130.00814.30
5.6.50.0130.00914.27
5.6.40.0140.00914.29
5.6.30.0140.00814.31
5.6.20.0120.01014.28
5.6.10.0130.00914.29
5.6.00.0120.00914.48
5.3.290.0070.00312.65

preferences:
36.13 ms | 403 KiB | 5 Q