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(int $length = 64, string $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'): string { if ($length < 1) { throw new \RangeException("Length must be a positive integer"); } $pieces = []; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $pieces []= $keyspace[random_int(0, $max)]; } return implode('', $pieces); } $a = random_str(32); $b = random_str(8, 'abcdefghijklmnopqrstuvwxyz'); $c = random_str(); var_dump($a, $b, $c);

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.4.90.0070.01116.34
7.4.80.0100.01016.46
7.4.70.0120.00716.25
7.4.60.0070.01216.34
7.4.50.0120.00816.30
7.4.40.0120.00716.31
7.4.30.0120.00916.47
7.4.20.0070.01316.32
7.4.10.0100.01116.45
7.4.00.0090.01116.49
7.3.210.0130.00616.58
7.3.200.0140.00616.48
7.3.190.0150.00416.23
7.3.180.0110.00916.34
7.3.170.0110.00716.40
7.3.160.0080.01016.35
7.3.150.0080.01116.47
7.3.140.0110.01016.52
7.3.130.0100.00916.27
7.3.120.0110.00816.57
7.3.110.0070.01316.38
7.3.100.0130.00816.32
7.3.90.0140.01316.31
7.3.80.0090.01216.32
7.3.70.0120.00715.89
7.3.60.0080.01416.02
7.3.50.0090.01016.00
7.3.40.0070.01316.04
7.3.30.0110.00815.91
7.3.20.0090.01116.00
7.3.10.0130.00815.91
7.3.00.0160.00916.02
7.2.330.0200.00616.43
7.2.320.0180.00316.56
7.2.310.0080.01316.50
7.2.300.0130.00916.77
7.2.290.0080.01016.50
7.2.280.0110.01216.68
7.2.270.0090.01116.59
7.2.260.0130.00816.70
7.2.250.0160.00616.74
7.2.240.0140.00816.57
7.2.230.0130.01116.52
7.2.220.0120.01216.67
7.2.210.0110.01016.58
7.2.200.0100.00916.13
7.2.190.0120.01016.17
7.2.180.0120.00916.19
7.2.170.0090.00916.18
7.2.160.0110.00716.16
7.2.150.0250.01016.18
7.2.140.0110.01016.20
7.2.130.0290.00516.25
7.2.120.0140.00716.19
7.2.110.0200.01116.20
7.2.100.0140.00816.12
7.2.90.0110.01116.13
7.2.80.0110.00916.28
7.2.70.0130.00816.24
7.2.60.0210.00916.23
7.2.50.0130.01016.16
7.2.40.0200.00616.23
7.2.30.0170.00416.20
7.2.20.0110.01316.29
7.2.10.0160.00916.24
7.2.00.0170.00616.25
7.1.330.0170.01015.53
7.1.320.0210.00815.67
7.1.310.0220.00815.51
7.1.300.0150.01115.10
7.1.290.0170.00815.15
7.1.280.0180.00715.15
7.1.270.0170.00715.18
7.1.260.0140.01015.17
7.1.250.0140.01015.17
7.1.240.0160.00715.51
7.1.230.0200.00715.54
7.1.220.0180.00915.57
7.1.210.0210.00715.49
7.1.200.0140.00915.44
7.1.190.0180.00815.60
7.1.180.0100.01515.41
7.1.170.0150.01015.61
7.1.160.0170.01015.59
7.1.150.0280.01115.63
7.1.140.0170.00815.59
7.1.130.0150.01115.60
7.1.120.0210.00715.61
7.1.110.0170.00915.65
7.1.100.0230.01015.69
7.1.90.0220.00815.57
7.1.80.0250.00915.56
7.1.70.0220.01015.60
7.1.60.0230.01215.46
7.1.50.0270.00715.52
7.1.40.0190.00715.59
7.1.30.0230.00715.53
7.1.20.0210.00815.68
7.1.10.0170.00915.70
7.1.00.0330.00615.62
7.0.330.0160.00815.26
7.0.320.0210.00615.20
7.0.310.0130.01015.08
7.0.300.0110.01115.11
7.0.290.0160.01115.30
7.0.280.0190.00815.22
7.0.270.0180.00715.33
7.0.260.0210.00515.35
7.0.250.0200.00615.32
7.0.240.0170.00815.26
7.0.230.0160.01115.30
7.0.220.0160.01315.29
7.0.210.0150.01215.23
7.0.200.0200.01015.40
7.0.190.0160.01215.35
7.0.180.0180.01215.23
7.0.170.0240.00415.26
7.0.160.0200.01215.28
7.0.150.0230.00715.21
7.0.140.0220.00515.38
7.0.130.0210.00815.18
7.0.120.0240.00715.36
7.0.110.0180.01115.38
7.0.100.0140.01215.19
7.0.90.0200.00915.21
7.0.80.0180.01315.30
7.0.70.0190.01115.23
7.0.60.0220.00715.35
7.0.50.0210.00715.32
7.0.40.0260.00615.30
7.0.30.0170.00915.32
7.0.20.0250.00615.18
7.0.10.0160.01415.31
7.0.00.0200.00715.32
5.6.400.0140.01115.67
5.6.390.0150.00915.44
5.6.380.0190.00815.66
5.6.370.0130.01215.61
5.6.360.0160.01115.81
5.6.350.0160.00915.64
5.6.340.0130.01515.80
5.6.330.0180.00915.69
5.6.320.0190.00815.65
5.6.310.0160.01315.58
5.6.300.0190.01215.69
5.6.290.0170.01315.54
5.6.280.0190.00815.67
5.6.270.0180.00915.81
5.6.260.0190.01115.73
5.6.250.0180.01115.66
5.6.240.0200.01015.72
5.6.230.0220.00815.80
5.6.220.0200.01115.68
5.6.210.0170.01315.74
5.6.200.0210.01015.76
5.6.190.0160.01115.55
5.6.180.0180.01415.77
5.6.170.0230.00715.63
5.6.160.0210.00915.63
5.6.150.0210.00815.57
5.6.140.0110.01815.61
5.6.130.0180.01015.73
5.6.120.0200.00615.74
5.6.110.0160.01315.58
5.6.100.0180.01115.62
5.6.90.0150.01415.75
5.6.80.0180.01115.49
5.6.70.0170.01215.59
5.6.60.0170.01315.70
5.6.50.0180.00915.50
5.6.40.0100.01715.48
5.6.30.0150.01215.58
5.6.20.0180.01115.52
5.6.10.0180.01015.67
5.6.00.0150.01315.66
5.5.380.0170.01315.48
5.5.370.0160.01315.48
5.5.360.0180.01115.58
5.5.350.0160.01515.63
5.5.340.0240.00615.60
5.5.330.0180.01115.68
5.5.320.0210.00915.57
5.5.310.0170.01115.57
5.5.300.0210.00915.59
5.5.290.0210.00715.48
5.5.280.0210.00815.65
5.5.270.0140.01315.61
5.5.260.0150.01315.47
5.5.250.0230.00715.58
5.5.240.0180.01215.52
5.5.230.0240.00815.52
5.5.220.0180.01215.56
5.5.210.0220.00715.51
5.5.200.0170.00915.55
5.5.190.0160.01315.49
5.5.180.0180.01115.53
5.5.170.0180.00915.48
5.5.160.0170.00915.66
5.5.150.0210.01115.65
5.5.140.0210.00915.42
5.5.130.0210.00915.50
5.5.120.0200.01115.56
5.5.110.0190.01515.34
5.5.100.0210.00915.56
5.5.90.0200.00815.51
5.5.80.0150.01515.70
5.5.70.0270.00715.46
5.5.60.0220.00915.61
5.5.50.0180.01315.53
5.5.40.0180.01115.48
5.5.30.0220.00815.54
5.5.20.0180.01515.56
5.5.10.0180.01015.47
5.5.00.0150.01215.40
5.4.450.0130.00712.83
5.4.440.0120.00912.79
5.4.430.0140.00612.80
5.4.420.0100.01012.75
5.4.410.0140.00712.76
5.4.400.0200.01012.76
5.4.390.0140.00912.64
5.4.380.0180.00512.79
5.4.370.0140.01012.70
5.4.360.0120.00812.74
5.4.350.0130.00812.69
5.4.340.0140.00912.74
5.4.330.0120.00812.76
5.4.320.0130.01112.73
5.4.310.0140.00812.71
5.4.300.0140.00812.71
5.4.290.0140.00912.54
5.4.280.0150.01112.61
5.4.270.0190.00712.78
5.4.260.0150.00712.67
5.4.250.0150.00712.69
5.4.240.0200.00212.65
5.4.230.0150.00812.66
5.4.220.0160.01012.67
5.4.210.0170.00612.74
5.4.200.0130.01012.68
5.4.190.0150.00512.82
5.4.180.0120.01112.66
5.4.170.0170.00612.69
5.4.160.0150.00612.66
5.4.150.0160.00612.85
5.4.140.0130.00912.68
5.4.130.0120.00912.79
5.4.120.0150.00712.79
5.4.110.0170.00712.76
5.4.100.0170.00512.75
5.4.90.0120.00912.74
5.4.80.0180.00512.70
5.4.70.0150.00812.78
5.4.60.0150.00712.73
5.4.50.0120.01212.68
5.4.40.0100.01212.74
5.4.30.0130.00812.70
5.4.20.0140.00912.71
5.4.10.0140.01112.71
5.4.00.0150.00612.71
5.3.290.0150.00813.06
5.3.280.0110.01112.95
5.3.270.0170.00713.02
5.3.260.0130.01013.07
5.3.250.0140.00913.01
5.3.240.0130.01212.88
5.3.230.0160.00813.00
5.3.220.0180.00512.90
5.3.210.0190.00612.96
5.3.200.0120.01012.93
5.3.190.0150.00813.09
5.3.180.0140.00913.04
5.3.170.0150.00813.10
5.3.160.0150.00813.08
5.3.150.0140.00613.08
5.3.140.0130.00913.08
5.3.130.0110.01013.04
5.3.120.0110.01013.01
5.3.110.0090.01312.99
5.3.100.0110.00813.01
5.3.90.0150.00813.05
5.3.80.0130.00613.03
5.3.70.0150.00613.03
5.3.60.0080.00913.06
5.3.50.0130.00613.00
5.3.40.0190.00512.92
5.3.30.0150.00712.97
5.3.20.0120.01012.94
5.3.10.0110.00912.79
5.3.00.0100.00812.87
5.2.170.0110.00812.39
5.2.160.0080.01212.36
5.2.150.0110.00712.40
5.2.140.0120.00812.47
5.2.130.0050.01212.31
5.2.120.0100.00712.33
5.2.110.0150.00512.41
5.2.100.0110.00712.29
5.2.90.0080.01012.36
5.2.80.0130.00812.27
5.2.70.0070.01312.45
5.2.60.0070.00912.27
5.2.50.0090.00912.31
5.2.40.0120.00512.38
5.2.30.0110.00912.26
5.2.20.0080.01012.16
5.2.10.0080.00912.12
5.2.00.0110.00612.08
5.1.60.0100.00611.81
5.1.50.0090.00811.77
5.1.40.0140.00511.79
5.1.30.0070.00911.85
5.1.20.0100.00711.82
5.1.10.0120.00611.77
5.1.00.0110.00511.75
5.0.50.0060.00811.57
5.0.40.0070.00611.57
5.0.30.0040.00911.57
5.0.20.0080.00611.57
5.0.10.0070.00711.57
5.0.00.0070.00511.57
4.4.90.0060.00311.57
4.4.80.0030.00511.57
4.4.70.0070.00211.57
4.4.60.0040.00411.57
4.4.50.0050.00311.57
4.4.40.0050.00311.57
4.4.30.0070.00211.57
4.4.20.0100.00011.57
4.4.10.0050.00211.57
4.4.00.0050.00311.57
4.3.110.0050.00311.57
4.3.100.0040.00511.57
4.3.90.0070.00311.57
4.3.80.0070.00211.57
4.3.70.0030.00511.57
4.3.60.0050.00311.57
4.3.50.0060.00211.57
4.3.40.0060.00311.57
4.3.30.0040.00411.57
4.3.20.0050.00311.57
4.3.10.0040.00411.57
4.3.00.0030.00611.57

preferences:
37.92 ms | 400 KiB | 5 Q