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') { $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(32)); var_dump(random_str(8, 'abcdefghijklmnopqrstuvwxyz'));

Here you find the average performance (time & memory) of each version. A greyed 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.2.20.0320.01318.83
7.2.10.0230.01118.58
7.2.00.0230.01118.41
7.1.140.0210.01117.83
7.1.130.0270.01017.37
7.1.120.0240.00917.42
7.1.110.0290.00916.87
7.1.100.0230.01016.88
7.1.90.0310.01016.74
7.1.80.0360.01116.68
7.1.70.0210.00815.84
7.1.60.0370.01333.90
7.1.50.0340.01433.65
7.1.40.0640.01433.29
7.1.30.0400.01433.43
7.1.20.0380.01133.43
7.1.10.0150.01315.35
7.1.00.0160.01115.46
7.0.270.0240.00817.12
7.0.260.0330.00817.09
7.0.250.0220.01116.47
7.0.240.0190.01016.46
7.0.230.0300.00916.44
7.0.220.0370.00916.21
7.0.210.0200.01115.39
7.0.200.0250.01215.51
7.0.190.0220.01015.43
7.0.180.0210.01315.06
7.0.170.0230.01215.08
7.0.160.0200.01115.11
7.0.150.0160.01015.05
7.0.140.0190.01015.13
7.0.130.0140.01215.40
7.0.120.0160.00915.30
7.0.110.0180.01015.14
7.0.100.0180.01115.15
7.0.90.0150.01015.16
7.0.80.0540.01215.22
7.0.70.0170.00915.09
7.0.60.0190.00714.98
7.0.50.0100.01015.22
7.0.40.0570.01215.21
7.0.30.0200.01115.22
7.0.20.0170.01015.11
7.0.10.0180.00915.13
7.0.00.0270.01115.23
hhvm-3.22.00.0890.22390.24
hhvm-3.21.30.0750.20290.15
hhvm-3.21.00.0980.20989.95
hhvm-3.20.20.1040.22090.16
hhvm-3.19.20.0980.21089.24
hhvm-3.18.50.0740.19488.08
hhvm-3.18.40.0970.21487.75
hhvm-3.17.30.0920.18887.37
hhvm-3.15.40.0870.19585.20
hhvm-3.13.20.1130.21196.42
hhvm-3.12.140.1020.19495.38
hhvm-3.11.10.1000.19387.44
hhvm-3.10.10.0790.19384.66
5.6.300.0170.06320.78
5.6.290.0160.06220.85
5.6.280.0140.06420.87
5.6.270.0140.06220.85
5.6.260.0140.06320.82
5.6.250.0140.06520.85
5.6.240.0170.06320.89
5.6.230.0210.06320.91
5.6.220.0110.06720.85
5.6.210.0190.06420.85
5.6.200.0180.06320.84
5.6.190.0170.06920.84
5.6.180.0140.06520.87
5.6.170.0180.05920.92
5.6.160.0170.06120.78
5.6.150.0150.06820.85
5.6.140.0140.06820.79
5.6.130.0130.06220.83
5.6.120.0180.06120.79
5.6.110.0140.06420.86
5.6.100.0170.06720.77
5.6.90.0130.05720.79
5.6.80.0140.05920.25
5.6.70.0170.05720.18
5.6.60.0170.06420.10
5.6.50.0150.06120.26
5.6.40.0120.06020.13
5.6.30.0120.06620.19
5.6.20.0160.07120.14
5.6.10.0150.05720.13
5.6.00.0140.05620.15
5.5.380.0110.06817.54
5.5.370.0150.06517.47
5.5.360.0150.06117.47
5.5.350.0120.06017.56
5.5.340.0170.05517.92
5.5.330.0180.05517.92
5.5.320.0150.06217.94
5.5.310.0110.07217.94
5.5.300.0160.06017.94
5.5.290.0160.06217.96
5.5.280.0160.06117.90
5.5.270.0140.05817.99
5.5.260.0180.06418.02
5.5.250.0100.06017.73
5.5.240.0140.06117.37
5.5.230.0120.06717.21
5.5.220.0150.05417.35
5.5.210.0130.06017.30
5.5.200.0150.05517.38
5.5.190.0170.05917.29
5.5.180.0120.06817.36
5.5.160.0110.06017.30
5.5.150.0140.06017.31
5.5.140.0120.06017.24
5.5.130.0120.05617.43
5.5.120.0150.05317.35
5.5.110.0130.06017.33
5.5.100.0130.05617.21
5.5.90.0150.05517.17
5.5.80.0180.05717.30
5.5.70.0140.05617.09
5.5.60.0140.06217.18
5.5.50.0130.05717.21
5.5.40.0110.05717.28
5.5.30.0120.06117.29
5.5.20.0110.06617.25
5.5.10.0140.06017.25
5.5.00.0150.05417.24
5.4.450.0180.06119.36
5.4.440.0140.06219.36
5.4.430.0170.05719.27
5.4.420.0130.06019.39
5.4.410.0100.06019.11
5.4.400.0150.05219.10
5.4.390.0130.06319.00
5.4.380.0140.05719.01
5.4.370.0140.05819.08
5.4.360.0140.06218.97
5.4.350.0170.05918.98
5.4.340.0120.06119.05
5.4.320.0170.05919.01
5.4.310.0110.06119.05
5.4.300.0130.05418.97
5.4.290.0080.06118.95
5.4.280.0120.06119.12
5.4.270.0120.05419.04
5.4.260.0150.05218.99
5.4.250.0130.05419.01
5.4.240.0160.05819.03
5.4.230.0140.05419.05
5.4.220.0130.06318.91
5.4.210.0170.05419.08
5.4.200.0090.06018.93
5.4.190.0130.06019.01
5.4.180.0140.06119.04
5.4.170.0120.06018.98
5.4.160.0140.05519.03
5.4.150.0120.06119.04
5.4.140.0150.06116.53
5.4.130.0120.05616.59
5.4.120.0130.05316.56
5.4.110.0150.05416.56
5.4.100.0110.05116.58
5.4.90.0090.05816.61
5.4.80.0150.05516.58
5.4.70.0110.06316.61
5.4.60.0120.05816.54
5.4.50.0140.05316.60
5.4.40.0120.05616.53
5.4.30.0130.05216.61
5.4.20.0130.05116.48
5.4.10.0150.05316.51
5.4.00.0130.05216.02
5.3.290.0130.06114.81
5.3.280.0130.05214.84
5.3.270.0110.06114.70
5.3.260.0140.06014.74
5.3.250.0100.05814.74
5.3.240.0140.06214.81
5.3.230.0110.05614.79
5.3.220.0130.05614.68
5.3.210.0170.05414.59
5.3.200.0100.05914.72
5.3.190.0120.06014.72
5.3.180.0120.05814.77
5.3.170.0140.05814.68
5.3.160.0120.05814.76
5.3.150.0140.05614.79
5.3.140.0130.05814.68
5.3.130.0150.05814.67
5.3.120.0130.05714.72
5.3.110.0120.05714.69
5.3.100.0120.06114.21
5.3.90.0120.05214.12
5.3.80.0140.05214.17
5.3.70.0120.05114.19
5.3.60.0100.05814.19
5.3.50.0170.05514.07
5.3.40.0150.05214.14
5.3.30.0100.05414.00
5.3.20.0090.05813.79
5.3.10.0130.05313.80
5.3.00.0080.05813.81
5.2.170.0110.04511.26
5.2.160.0130.04511.29
5.2.150.0090.04411.27
5.2.140.0080.04511.29
5.2.130.0100.04311.33
5.2.120.0120.03911.23
5.2.110.0090.04311.08
5.2.100.0090.04211.24
5.2.90.0100.04411.19
5.2.80.0100.04211.22
5.2.70.0090.04711.28
5.2.60.0090.04911.22
5.2.50.0110.05211.20
5.2.40.0090.04611.20
5.2.30.0100.04611.14
5.2.20.0100.04411.08
5.2.10.0080.04311.13
5.2.00.0100.04510.93
5.1.60.0080.03610.06
5.1.50.0080.03910.11
5.1.40.0070.03410.15
5.1.30.0100.03810.49
5.1.20.0100.03810.55
5.1.10.0060.04010.11
5.1.00.0080.03910.18
5.0.50.0070.0289.15
5.0.40.0070.0319.15
5.0.30.0040.0489.15
5.0.20.0080.0289.15
5.0.10.0060.0289.15
5.0.00.0080.0429.15
4.4.90.0070.0199.15
4.4.80.0040.0249.15
4.4.70.0040.0269.15
4.4.60.0060.0239.15
4.4.50.0050.0239.15
4.4.40.0040.0359.15
4.4.30.0060.0239.15
4.4.20.0070.0219.15
4.4.10.0050.0289.15
4.4.00.0060.0379.15
4.3.110.0060.0229.15
4.3.100.0040.0239.15
4.3.90.0050.0229.15
4.3.80.0060.0339.15
4.3.70.0060.0199.15
4.3.60.0070.0219.15
4.3.50.0040.0239.15
4.3.40.0050.0339.15
4.3.30.0030.0249.15
4.3.20.0020.0259.15
4.3.10.0050.0239.15
4.3.00.0060.0219.15