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(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.2.10.0000.00817.61
8.2.00.0000.01217.66
8.1.140.0050.00517.43
8.1.130.0110.00017.33
8.1.120.0030.00617.39
8.1.110.0140.00017.48
8.1.100.0110.00417.49
8.1.90.0110.00717.33
8.1.80.0070.01017.36
8.1.70.0130.00317.45
8.1.60.0130.00317.66
8.1.50.0190.00017.59
8.1.40.0040.00817.44
8.1.30.0130.00017.61
8.1.20.0070.00717.65
8.1.10.0060.00617.71
8.1.00.0080.00517.47
8.0.270.0000.01016.77
8.0.260.0030.00816.77
8.0.250.0040.00716.88
8.0.240.0030.00716.87
8.0.230.0070.00416.81
8.0.220.0080.00416.76
8.0.210.0110.00316.80
8.0.200.0060.00616.75
8.0.190.0120.00216.69
8.0.180.0070.00416.85
8.0.170.0090.00416.80
8.0.160.0040.00616.80
8.0.150.0070.00716.68
8.0.140.0080.00416.77
8.0.130.0080.00416.73
8.0.120.0060.00616.67
8.0.110.0040.00816.74
8.0.100.0100.00316.76
8.0.90.0100.00016.66
8.0.80.0070.01016.79
8.0.70.0100.00316.69
8.0.60.0070.00716.80
8.0.50.0040.00816.79
8.0.30.0100.00316.80
8.0.20.0090.00316.88
8.0.10.0110.00316.83
8.0.00.0040.00816.80
7.4.330.0090.00012.61
7.4.320.0060.01116.45
7.4.300.0080.00816.35
7.4.290.0140.00316.47
7.4.280.0120.00616.53
7.4.270.0190.00016.38
7.4.260.0140.00416.48
7.4.250.0110.00716.50
7.4.240.0120.00516.39
7.4.230.0110.00616.41
7.4.220.0100.00516.47
7.4.210.0110.00416.52
7.4.200.0110.00416.47
7.4.190.0070.00716.63
7.4.180.0120.00416.43
7.4.160.0070.00716.52
7.4.150.0070.00716.45
7.4.140.0110.00516.35
7.4.130.0090.00516.39
7.4.120.0070.00716.53
7.4.110.0130.00316.34
7.4.100.0090.00516.41
7.4.90.0140.00016.40
7.4.80.0150.00016.43
7.4.70.0150.00016.34
7.4.60.0130.00016.35
7.4.50.0110.00816.35
7.4.40.0090.00816.33
7.4.30.0110.00616.36
7.4.20.0040.01416.38
7.4.10.0130.00516.46
7.4.00.0130.00616.03
7.3.330.0050.00516.18
7.3.320.0090.00616.28
7.3.310.0110.00416.21
7.3.300.0100.00516.11
7.3.290.0100.00516.13
7.3.280.0070.00716.15
7.3.270.0090.00616.02
7.3.260.0130.00316.20
7.3.250.0110.00416.08
7.3.240.0120.00316.09
7.3.230.0140.00316.28
7.3.220.0140.00016.16
7.3.210.0130.00316.22
7.3.200.0160.00016.08
7.3.190.0080.00616.16
7.3.180.0140.00016.28
7.3.170.0120.00616.35
7.3.160.0120.00516.29
7.3.150.0090.01016.38
7.3.140.0100.00716.21
7.3.130.0070.01216.36
7.3.120.0120.00615.94
7.3.110.0050.01215.68
7.3.100.0100.00515.62
7.3.90.0090.00915.83
7.3.80.0090.00815.58
7.3.70.0090.00615.62
7.3.60.0080.00915.57
7.3.50.0100.00815.55
7.3.40.0120.00415.56
7.3.30.0080.00915.47
7.3.20.0130.00615.87
7.3.10.0110.00915.96
7.3.00.0090.00715.96
7.2.340.0110.00416.32
7.2.330.0110.00616.40
7.2.320.0110.00616.42
7.2.310.0140.00316.32
7.2.300.0130.00316.26
7.2.290.0090.00916.47
7.2.280.0090.01116.39
7.2.270.0110.00716.54
7.2.260.0160.00616.50
7.2.250.0080.00916.26
7.2.240.0140.00515.90
7.2.230.0080.00915.98
7.2.220.0100.00715.95
7.2.210.0120.00815.64
7.2.200.0070.00815.87
7.2.190.0090.00815.78
7.2.180.0070.00915.85
7.2.170.0110.00615.82
7.2.160.0100.00615.75
7.2.150.0120.00616.10
7.2.140.0090.00816.17
7.2.130.0100.00816.29
7.2.120.0110.00816.28
7.2.110.0100.00716.22
7.2.100.0100.00816.21
7.2.90.0070.00816.29
7.2.80.0090.00716.24
7.2.70.0120.00916.18
7.2.60.0120.00416.24
7.2.50.0070.00916.21
7.2.40.0180.00916.69
7.2.30.0170.00916.73
7.2.20.0180.01016.86
7.2.10.0160.01016.83
7.2.00.0180.00816.83
7.1.330.0150.00914.92
7.1.320.0140.00814.90
7.1.310.0120.00915.02
7.1.300.0140.00714.99
7.1.290.0100.00815.03
7.1.280.0120.00714.99
7.1.270.0140.00515.04
7.1.260.0120.00615.01
7.1.250.0100.00815.10
7.1.240.0120.00614.86
7.1.230.0110.00815.00
7.1.220.0100.00814.96
7.1.210.0120.00714.90
7.1.200.0110.00714.83
7.1.190.0110.00814.93
7.1.180.0120.00914.95
7.1.170.0120.00814.92
7.1.160.0210.00915.38
7.1.150.0190.00915.51
7.1.140.0220.00815.57
7.1.130.0190.00715.63
7.1.120.0180.01015.61
7.1.110.0270.00715.50
7.1.100.0190.01015.41
7.1.90.0180.00915.38
7.1.80.0190.01015.42
7.1.70.0190.00715.11
7.1.60.0220.01121.13
7.1.50.0290.01121.01
7.1.40.0250.01020.96
7.1.30.0180.01220.90
7.1.20.0300.01120.90
7.1.10.0130.00914.97
7.1.00.0140.00914.97
7.0.330.0150.00414.61
7.0.320.0150.00814.63
7.0.310.0150.00714.66
7.0.300.0140.00614.59
7.0.290.0190.00814.96
7.0.280.0130.00714.54
7.0.270.0180.01015.22
7.0.260.0200.00915.24
7.0.250.0190.00815.08
7.0.240.0200.00715.07
7.0.230.0210.00915.11
7.0.220.0200.01115.01
7.0.210.0180.00914.78
7.0.200.0160.00914.61
7.0.190.0180.00814.69
7.0.180.0140.00914.66
7.0.170.0130.01114.54
7.0.160.0250.00814.58
7.0.150.0170.00714.59
7.0.140.0160.00914.55
7.0.130.0160.00814.68
7.0.120.0160.00914.60
7.0.110.0150.01014.51
7.0.100.0160.00814.57
7.0.90.0160.00814.54
7.0.80.0130.00914.61
7.0.70.0150.00814.58
7.0.60.0120.01014.63
7.0.50.0170.01014.61
7.0.40.0140.00814.67
7.0.30.0170.00614.70
7.0.20.0170.00914.71
7.0.10.0170.00714.63
7.0.00.0180.00914.69
5.6.400.0120.00814.97
5.6.390.0110.00915.01
5.6.380.0110.01015.05
5.6.370.0180.00414.97
5.6.360.0150.00514.92
5.6.350.0120.00914.98
5.6.340.0120.00815.11
5.6.330.0130.00914.99
5.6.320.0150.00615.03
5.6.310.0100.01014.98
5.6.300.0150.02716.93
5.6.290.0150.02616.93
5.6.280.0130.02816.89
5.6.270.0130.03116.89
5.6.260.0160.02916.89
5.6.250.0140.02816.97
5.6.240.0120.03016.89
5.6.230.0170.02616.94
5.6.220.0170.02516.93
5.6.210.0160.03217.04
5.6.200.0130.03116.89
5.6.190.0170.02417.01
5.6.180.0140.02516.99
5.6.170.0160.02516.89
5.6.160.0130.03116.92
5.6.150.0170.02816.96
5.6.140.0160.02816.86
5.6.130.0170.02916.88
5.6.120.0160.02516.96
5.6.110.0150.03216.96
5.6.100.0160.02916.94
5.6.90.0130.02816.97
5.6.80.0140.02516.71
5.6.70.0140.02416.65
5.6.60.0170.02616.70
5.6.50.0150.02816.76
5.6.40.0160.02516.71
5.6.30.0140.03116.67
5.6.20.0130.02516.66
5.6.10.0120.02916.68
5.6.00.0130.02516.69
5.5.380.0170.00215.23
5.5.370.0050.01315.09
5.5.360.0110.00815.03
5.5.350.0100.00915.12
5.5.340.0150.00415.15
5.5.330.0130.00615.13
5.5.320.0090.01115.08
5.5.310.0100.00815.13
5.5.300.0150.00615.06
5.5.290.0120.00915.24
5.5.280.0100.01015.30
5.5.270.0150.00715.17
5.5.260.0150.00815.24
5.5.250.0130.00715.20
5.5.240.0130.00615.13
5.5.230.0110.01015.15
5.5.220.0120.00714.97
5.5.210.0090.00815.16
5.5.200.0150.00615.04
5.5.190.0150.00414.93
5.5.180.0160.00315.06
5.5.170.0160.00515.06
5.5.160.0080.01215.00
5.5.150.0130.00815.01
5.5.140.0070.01415.03
5.5.130.0140.00714.81
5.5.120.0100.01115.09
5.5.110.0120.00815.00
5.5.100.0150.00414.99
5.5.90.0100.01114.93
5.5.80.0130.00515.08
5.5.70.0130.00615.08
5.5.60.0120.00615.07
5.5.50.0080.01014.93
5.5.40.0120.00615.04
5.5.30.0140.00715.02
5.5.20.0090.00814.98
5.5.10.0070.01014.86
5.5.00.0080.01015.07
5.4.450.0070.00712.63
5.4.440.0100.00612.69
5.4.430.0100.00512.73
5.4.420.0120.00312.57
5.4.410.0070.00612.58
5.4.400.0080.00512.56
5.4.390.0090.00512.63
5.4.380.0100.00512.63
5.4.370.0080.00712.57
5.4.360.0090.00412.57
5.4.350.0070.00712.58
5.4.340.0090.00612.52
5.4.330.0130.00512.59
5.4.320.0120.00312.70
5.4.310.0100.00612.61
5.4.300.0110.00512.61
5.4.290.0100.00612.60
5.4.280.0090.00612.63
5.4.270.0110.00412.63
5.4.260.0090.00612.56
5.4.250.0130.00312.60
5.4.240.0090.00512.59
5.4.230.0110.01212.53
5.4.220.0110.00512.59
5.4.210.0100.00512.57
5.4.200.0050.00812.54
5.4.190.0130.00312.53
5.4.180.0120.00412.58
5.4.170.0110.00412.53
5.4.160.0090.00612.58
5.4.150.0060.00812.58
5.4.140.0090.00712.61
5.4.130.0110.00412.51
5.4.120.0090.00612.54
5.4.110.0070.00912.54
5.4.100.0090.00412.56
5.4.90.0060.00812.58
5.4.80.0110.00312.58
5.4.70.0080.00712.62
5.4.60.0100.00512.58
5.4.50.0110.00612.59
5.4.40.0120.00412.50
5.4.30.0120.00312.61
5.4.20.0090.00812.55
5.4.10.0100.00612.53
5.4.00.0110.00412.61
5.3.290.0110.00712.94
5.3.280.0080.00712.83
5.3.270.0090.00712.90
5.3.260.0140.00312.94
5.3.250.0110.00712.99
5.3.240.0090.00912.87
5.3.230.0100.00612.94
5.3.220.0100.00512.85
5.3.210.0110.00512.83
5.3.200.0070.00912.81
5.3.190.0100.00612.84
5.3.180.0080.00812.98
5.3.170.0080.00512.96
5.3.160.0120.00612.98
5.3.150.0080.00912.99
5.3.140.0080.00812.88
5.3.130.0090.00812.91
5.3.120.0130.00212.93
5.3.110.0110.00412.93
5.3.100.0090.00812.83
5.3.90.0100.00412.97
5.3.80.0070.00712.83
5.3.70.0060.00812.84
5.3.60.0120.00412.92
5.3.50.0070.00712.84
5.3.40.0120.00512.82
5.3.30.0100.00712.87
5.3.20.0070.00712.88
5.3.10.0100.00712.78
5.3.00.0090.00512.74
5.2.170.0050.00712.39
5.2.160.0070.00712.39
5.2.150.0040.00812.39
5.2.140.0100.00412.46
5.2.130.0050.00812.48
5.2.120.0100.00412.39
5.2.110.0070.00612.41
5.2.100.0120.00112.41
5.2.90.0100.00312.41
5.2.80.0070.00712.39
5.2.70.0080.00612.39
5.2.60.0060.00712.33
5.2.50.0080.00612.34
5.2.40.0070.00512.42
5.2.30.0060.00612.34
5.2.20.0070.00612.32
5.2.10.0090.00512.28
5.2.00.0060.00712.28
5.1.60.0060.00712.28
5.1.50.0050.00812.28
5.1.40.0070.00612.28
5.1.30.0060.00612.28
5.1.20.0060.00512.28
5.1.10.0050.00512.28
5.1.00.0070.00412.28
5.0.50.0050.00412.28
5.0.40.0060.00212.28
5.0.30.0040.00512.28
5.0.20.0040.00612.28
5.0.10.0070.00212.28
5.0.00.0060.00312.28
4.4.90.0040.00312.28
4.4.80.0030.00412.28
4.4.70.0060.00012.28
4.4.60.0040.00212.28
4.4.50.0050.00112.28
4.4.40.0030.00312.28
4.4.30.0040.00212.28
4.4.20.0070.00012.28
4.4.10.0030.00312.28
4.4.00.0000.00612.28
4.3.110.0030.00312.28
4.3.100.0040.00212.28
4.3.90.0030.00312.28
4.3.80.0040.00212.28
4.3.70.0050.00212.28
4.3.60.0030.00412.28
4.3.50.0020.00512.28
4.3.40.0030.00312.28
4.3.30.0040.00212.28
4.3.20.0030.00212.28
4.3.10.0030.00212.28
4.3.00.0020.00312.28

preferences:
45.35 ms | 401 KiB | 5 Q