3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?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).
Note: hhvm uses a JIT which only kicks in after a few runs. Since we run scripts only once, hhvm always runs slower.

VersionSystem time (s)User time (s)Memory (MiB)
7.3.10.0540.00014.78
7.3.00.0500.00814.65
7.2.130.0520.00714.92
7.2.120.0660.00714.82
7.2.110.0570.00714.73
7.2.100.0560.00814.84
7.2.90.0560.00714.85
7.2.80.0540.00814.82
7.2.70.0550.00715.05
7.2.60.0490.00815.00
7.2.50.0550.00714.99
7.2.40.0480.00715.05
7.2.30.0520.00815.09
7.2.20.0550.00715.01
7.2.10.0560.00815.00
7.2.00.0550.00815.06
7.1.250.0460.00713.91
7.1.240.0660.00713.90
7.1.230.0560.00813.89
7.1.220.0610.00813.85
7.1.210.0590.00713.93
7.1.200.0580.00813.93
7.1.190.0520.00713.92
7.1.180.0610.00613.89
7.1.170.0490.00713.86
7.1.160.0510.00713.92
7.1.150.0450.00813.92
7.1.140.0510.00813.98
7.1.130.0540.00813.96
7.1.120.0580.00813.94
7.1.110.0510.00813.97
7.1.100.0550.00713.95
7.1.90.0490.00813.99
7.1.80.0580.00813.99
7.1.70.0450.00713.94
7.1.60.0560.00719.81
7.1.50.0530.00819.78
7.1.40.0490.00819.70
7.1.30.0460.00919.77
7.1.20.0470.00919.75
7.1.10.0430.00713.90
7.1.00.0400.00713.95
7.0.330.0440.00613.54
7.0.320.0760.00613.49
7.0.310.0600.00813.65
7.0.300.0560.00713.58
7.0.290.0590.00813.67
7.0.280.0470.00813.56
7.0.270.0580.00513.56
7.0.260.0520.00713.63
7.0.250.0530.00813.63
7.0.240.0480.00813.70
7.0.230.0550.00813.68
7.0.220.0520.00813.63
7.0.210.0510.00813.63
7.0.200.0620.00813.60
7.0.190.0530.00713.68
7.0.180.0400.00813.65
7.0.170.0460.00713.66
7.0.160.0410.00913.67
7.0.150.0420.00813.62
7.0.140.0420.00713.72
7.0.130.0390.00713.72
7.0.120.0440.00713.65
7.0.110.0480.00713.65
7.0.100.0390.00713.63
7.0.90.0390.00813.66
7.0.80.0390.00513.60
7.0.70.0380.00913.71
7.0.60.0360.00913.67
7.0.50.0380.00813.72
7.0.40.0430.00713.68
7.0.30.0340.00913.70
7.0.20.0440.00613.72
7.0.10.0360.00713.70
7.0.00.0370.00713.69
hhvm-3.22.00.1340.18390.74
hhvm-3.21.30.1080.17790.06
hhvm-3.21.00.1150.17790.19
hhvm-3.20.20.1210.17790.46
hhvm-3.19.20.1180.17889.68
hhvm-3.18.50.1080.17788.07
hhvm-3.18.40.1140.17388.20
hhvm-3.17.30.1010.15887.37
hhvm-3.15.40.0990.15685.22
hhvm-3.13.20.1190.16996.45
hhvm-3.12.140.1190.16295.55
hhvm-3.11.10.1130.16087.58
hhvm-3.10.10.1040.17084.81
5.6.380.0090.00814.18
5.6.370.0120.01014.20
5.6.360.0140.00714.20
5.6.350.0130.00814.22
5.6.340.0120.00814.23
5.6.330.0130.00914.27
5.6.320.0130.00814.26
5.6.310.0130.00814.24
5.6.300.0140.00714.27
5.6.290.0120.00914.35
5.6.280.0130.00814.18
5.6.270.0140.00714.29
5.6.260.0100.00914.25
5.6.250.0120.00914.31
5.6.240.0130.00714.26
5.6.230.0120.00714.22
5.6.220.0120.00814.24
5.6.210.0120.00814.22
5.6.200.0120.00914.20
5.6.190.0100.01014.21
5.6.180.0110.00914.27
5.6.170.0110.00914.18
5.6.160.0100.01014.19
5.6.150.0130.00714.24
5.6.140.0110.00914.21
5.6.130.0120.00814.22
5.6.120.0110.00914.20
5.6.110.0110.00814.15
5.6.100.0120.00714.24
5.6.90.0120.00814.27
5.6.80.0120.00814.16
5.6.70.0120.00814.10
5.6.60.0120.00814.16
5.6.50.0110.00814.12
5.6.40.0120.00714.14
5.6.30.0120.00714.15
5.6.20.0120.00814.15
5.6.10.0130.00714.16
5.6.00.0110.00914.15
5.5.380.0090.00711.17
5.5.370.0090.00711.14
5.5.360.0090.00611.09
5.5.350.0090.00611.13
5.5.340.0100.00611.09
5.5.330.0110.00411.14
5.5.320.0080.00611.12
5.5.310.0100.00411.11
5.5.300.0100.00611.18
5.5.290.0090.00711.13
5.5.280.0080.00611.11
5.5.270.0090.00511.14
5.5.260.0100.00511.07
5.5.250.0090.00511.09
5.5.240.0100.00511.05
5.5.230.0100.00511.03
5.5.220.0090.00611.06
5.5.210.0090.00611.04
5.5.200.0080.00711.03
5.5.190.0090.00611.07
5.5.180.0080.00611.08
5.5.170.0120.00713.41
5.5.160.0090.00511.02
5.5.150.0080.00611.12
5.5.140.0090.00511.04
5.5.130.0090.00611.02
5.5.120.0100.00511.01
5.5.110.0090.00510.99
5.5.100.0100.00611.08
5.5.90.0090.00611.07
5.5.80.0090.00511.07
5.5.70.0090.00611.02
5.5.60.0090.00611.02
5.5.50.0090.00611.03
5.5.40.0090.00511.04
5.5.30.0100.00411.04
5.5.20.0090.00611.02
5.5.10.0080.00611.01
5.5.00.0100.00511.04
5.4.450.0090.00611.07
5.4.440.0100.00411.08
5.4.430.0100.00611.02
5.4.420.0100.00511.02
5.4.410.0080.00611.05
5.4.400.0090.00611.02
5.4.390.0080.00611.02
5.4.380.0090.00611.02
5.4.370.0100.00510.98
5.4.360.0090.00611.02
5.4.350.0090.00510.97
5.4.340.0090.00511.00
5.4.330.0090.00510.98
5.4.320.0090.00510.96
5.4.310.0100.00511.00
5.4.300.0090.00511.00
5.4.290.0100.00510.98
5.4.280.0090.00610.97
5.4.270.0090.00611.01
5.4.260.0090.00510.99
5.4.250.0100.00510.99
5.4.240.0090.00511.00
5.4.230.0100.00410.96
5.4.220.0080.00610.94
5.4.210.0090.00510.97
5.4.200.0100.00510.98
5.4.190.0080.00610.94
5.4.180.0090.00510.91
5.4.170.0080.00611.01
5.4.160.0070.00711.00
5.4.150.0100.00510.99
5.4.140.0100.00411.03
5.4.130.0080.00611.00
5.4.120.0080.00711.02
5.4.110.0070.00711.01
5.4.100.0100.00410.98
5.4.90.0080.00711.05
5.4.80.0080.00610.99
5.4.70.0090.00611.01
5.4.60.0080.00610.97
5.4.50.0080.00611.00
5.4.40.0100.00511.04
5.4.30.0090.00510.99
5.4.20.0100.00511.07
5.4.10.0090.00511.03
5.4.00.0090.00511.01
5.3.290.0090.00510.47
5.3.280.0080.00610.38
5.3.270.0100.00310.41
5.3.260.0080.00510.41
5.3.250.0090.00510.43
5.3.240.0080.00510.31
5.3.230.0080.00610.39
5.3.220.0080.00510.38
5.3.210.0090.00410.39
5.3.200.0090.00510.35
5.3.190.0090.00510.38
5.3.180.0080.00610.47
5.3.170.0070.00610.48
5.3.160.0090.00410.50
5.3.150.0090.00410.51
5.3.140.0090.00610.48
5.3.130.0080.00510.42
5.3.120.0090.00510.43
5.3.110.0100.00410.45
5.3.100.0090.00510.45
5.3.90.0070.00610.47
5.3.80.0080.00610.40
5.3.70.0080.00610.39
5.3.60.0080.00510.46
5.3.50.0080.00410.39
5.3.40.0090.00510.38
5.3.30.0090.00510.37
5.3.20.0080.00510.41
5.3.10.0090.00410.28
5.3.00.0080.00510.27
5.2.170.0050.0069.85
5.2.160.0070.0049.87
5.2.150.0070.0059.84
5.2.140.0060.0069.86
5.2.130.0070.0049.84
5.2.120.0070.0049.85
5.2.110.0070.0059.82
5.2.100.0060.0059.82
5.2.90.0080.0049.84
5.2.80.0080.0049.80
5.2.70.0070.0049.79
5.2.60.0080.0049.78
5.2.50.0070.0049.83
5.2.40.0080.0049.79
5.2.30.0080.0039.81
5.2.20.0080.0039.75
5.2.10.0080.0039.73
5.2.00.0080.0039.71
5.1.60.0060.0039.67
5.1.50.0050.0059.68
5.1.40.0050.0059.67
5.1.30.0060.0049.69
5.1.20.0060.0059.68
5.1.10.0060.0039.68
5.1.00.0070.0039.67
5.0.50.0050.0039.67
5.0.40.0050.0049.67
5.0.30.0040.0049.67
5.0.20.0050.0039.67
5.0.10.0050.0039.67
5.0.00.0050.0039.67
4.4.90.0040.0049.67
4.4.80.0030.0049.67
4.4.70.0040.0039.67
4.4.60.0040.0039.67
4.4.50.0040.0039.67
4.4.40.0030.0049.67
4.4.30.0050.0029.67
4.4.20.0040.0039.67
4.4.10.0040.0039.67
4.4.00.0040.0039.67
4.3.110.0040.0039.67
4.3.100.0040.0039.67
4.3.90.0040.0039.67
4.3.80.0040.0049.67
4.3.70.0050.0029.67
4.3.60.0040.0039.67
4.3.50.0040.0039.67
4.3.40.0040.0049.67
4.3.30.0040.0039.67
4.3.20.0040.0029.67
4.3.10.0030.0039.67
4.3.00.0030.0039.67