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)
8.4.140.0130.01117.58
8.4.130.0240.00917.48
8.4.120.0380.00917.45
8.4.110.0430.00917.57
8.4.100.0360.01017.41
8.4.90.0400.00917.59
8.4.80.0330.00917.63
8.4.70.0370.00917.49
8.4.60.0370.00817.56
8.4.50.0410.00817.54
8.4.40.0360.00717.41
8.4.30.0360.00817.42
8.4.20.0330.00717.38
8.4.10.0260.00917.98
8.3.270.0350.01116.37
8.3.260.0350.01216.43
8.3.250.0300.00816.43
8.3.240.0320.00916.41
8.3.230.0280.00816.39
8.3.220.0300.00916.41
8.3.210.0300.00716.43
8.3.200.0310.00716.48
8.3.190.0330.00816.53
8.3.180.0340.00716.37
8.3.170.0330.00616.49
8.3.160.0310.00716.53
8.3.150.0300.00716.54
8.3.140.0290.00716.51
8.3.130.0260.00816.36
8.3.120.0290.00716.50
8.3.110.0300.00616.55
8.3.100.0320.00819.45
8.3.90.0230.00820.76
8.3.80.0300.00817.13
8.3.70.0320.00717.16
8.3.60.0310.01018.40
8.3.50.0350.00917.29
8.3.40.0330.00918.15
8.3.30.0260.00718.10
8.3.20.0260.00618.12
8.3.10.0250.00818.11
8.3.00.0230.00718.10
8.2.290.0300.00916.49
8.2.280.0290.00916.48
8.2.270.0300.00716.44
8.2.260.0280.00716.49
8.2.250.0270.00816.44
8.2.240.0300.00616.39
8.2.230.0280.00716.37
8.2.220.0280.00816.45
8.2.210.0270.00817.14
8.2.200.0270.00917.16
8.2.190.0300.00717.14
8.2.180.0310.00717.17
8.2.170.0300.00818.34
8.2.160.0320.00818.86
8.2.150.0240.00819.46
8.2.140.0290.00919.00
8.2.130.0240.00821.91
8.2.120.0300.00918.20
8.2.110.0230.00819.51
8.2.100.0260.00618.29
8.2.90.0290.00718.20
8.2.80.0280.00918.13
8.2.70.0180.00543.98
8.2.60.0270.00621.93
8.2.50.0220.00921.42
8.2.40.0230.00621.17
8.2.30.0180.00520.50
8.2.20.0180.00620.89
8.2.10.0120.00719.47
8.2.00.0160.00720.17
8.1.330.0300.01016.10
8.1.320.0290.00816.02
8.1.310.0230.00716.21
8.1.300.0290.00816.11
8.1.290.0260.00716.89
8.1.280.0280.00816.93
8.1.270.0280.00717.84
8.1.260.0260.00917.90
8.1.250.0320.00717.88
8.1.240.0250.00918.14
8.1.230.0290.00617.91
8.1.220.0290.00617.95
8.1.210.0300.01017.81
8.1.200.0240.00721.34
8.1.190.0210.00721.70
8.1.180.0220.00421.31
8.1.170.0210.00621.25
8.1.160.0200.00721.01
8.1.150.0200.00820.96
8.1.140.0150.00519.79
8.1.130.0180.00820.10
8.1.120.0170.00619.94
8.1.110.0160.00619.63
8.1.100.0150.00619.17
8.1.90.0150.00519.20
8.1.80.0150.00619.17
8.1.70.0110.00618.53
8.1.60.0140.00518.87
8.1.50.0150.00618.89
8.1.40.0150.00618.95
8.1.30.0160.00518.87
8.1.20.0160.00518.67
8.1.10.0150.00518.49
8.1.00.0170.00518.58
8.0.300.0290.00719.11
8.0.290.0260.00721.30
8.0.280.0230.00620.64
8.0.270.0210.00720.17
8.0.260.0200.00519.75
8.0.250.0170.00519.47
8.0.240.0160.00519.30
8.0.230.0140.00718.84
8.0.220.0160.00618.80
8.0.210.0140.00618.66
8.0.200.0150.00618.60
8.0.190.0150.00518.51
8.0.180.0140.00518.38
8.0.170.0140.00718.39
8.0.160.0140.00518.11
8.0.150.0150.00518.00
8.0.140.0140.00517.89
8.0.130.0140.00617.95
8.0.120.0130.00517.14
8.0.110.0130.00517.70
8.0.100.0130.00517.69
8.0.90.0130.00517.65
8.0.80.0130.00617.53
8.0.70.0130.00617.59
8.0.60.0120.00617.62
8.0.50.0120.00517.62
8.0.30.0130.00617.39
8.0.20.0130.00617.47
8.0.10.0130.00717.44
8.0.00.0120.00617.45
7.4.330.0170.00518.84
7.4.320.0180.00418.84
7.4.300.0130.00418.08
7.4.290.0130.00517.84
7.4.280.0120.00517.59
7.4.270.0120.00517.42
7.4.260.0140.00517.56
7.4.250.0130.00517.16
7.4.240.0130.00517.41
7.4.230.0120.00517.36
7.4.220.0110.00517.29
7.4.210.0110.00517.29
7.4.200.0110.00517.32
7.4.190.0110.00517.39
7.4.180.0110.00617.38
7.4.160.0120.00617.17
7.4.150.0110.00617.09
7.4.140.0120.00617.10
7.4.130.0110.00717.06
7.4.120.0120.00617.05
7.4.110.0120.00716.96
7.4.100.0110.00717.00
7.4.90.0110.00716.95
7.4.80.0120.00716.90
7.4.70.0110.00716.90
7.4.60.0110.00716.87
7.4.50.0110.00816.75
7.4.40.0110.00716.75
7.4.30.0110.00716.78
7.4.20.0110.00716.74
7.4.10.0110.00816.72
7.4.00.0100.00716.70
7.3.330.0140.00517.36
7.3.320.0140.00517.24
7.3.310.0140.00517.33
7.3.300.0140.00517.25
7.3.290.0120.00517.02
7.3.280.0130.00617.04
7.3.270.0130.00616.89
7.3.260.0130.00616.89
7.3.250.0130.00616.86
7.3.240.0130.00716.85
7.3.230.0120.00716.82
7.3.220.0130.00716.79
7.3.210.0130.00716.79
7.3.200.0130.00716.76
7.3.190.0120.00716.75
7.3.180.0120.00716.74
7.3.170.0130.00716.71
7.3.160.0120.00716.72
7.3.150.0120.00716.69
7.3.140.0130.00716.68
7.3.130.0120.00716.66
7.3.120.0120.00716.55
7.3.110.0110.00816.47
7.3.100.0120.00716.31
7.3.90.0120.00816.36
7.3.80.0120.00716.25
7.3.70.0120.00716.28
7.3.60.0110.00816.32
7.3.50.0120.00716.29
7.3.40.0110.00716.29
7.3.30.0110.00816.29
7.3.20.0140.00816.78
7.3.10.0140.00716.74
7.3.00.0140.00816.75
7.2.340.0160.00716.92
7.2.330.0160.00716.86
7.2.320.0160.00716.86
7.2.310.0150.00716.80
7.2.300.0150.00816.82
7.2.290.0150.00816.79
7.2.280.0150.00816.78
7.2.270.0150.00816.76
7.2.260.0150.00816.75
7.2.250.0140.00816.71
7.2.240.0140.00816.63
7.2.230.0140.00816.50
7.2.220.0140.00816.42
7.2.210.0140.00816.38
7.2.200.0130.00816.44
7.2.190.0130.00816.41
7.2.180.0130.00816.40
7.2.170.0130.00816.43
7.2.160.0130.00816.42
7.2.150.0150.00816.95
7.2.140.0140.00816.94
7.2.130.0150.00817.02
7.2.120.0140.00816.97
7.2.110.0140.00816.97
7.2.100.0160.00816.97
7.2.90.0150.00816.94
7.2.80.0150.00816.95
7.2.70.0150.00916.95
7.2.60.0140.00816.95
7.2.50.0150.00816.95
7.2.40.0150.00816.97
7.2.30.0150.00816.99
7.2.20.0160.00916.97
7.2.10.0160.00816.97
7.2.00.0150.00817.00
7.1.330.0170.00816.28
7.1.320.0160.00816.04
7.1.310.0160.00816.02
7.1.300.0160.00815.98
7.1.290.0170.00815.97
7.1.280.0170.00815.98
7.1.270.0160.00715.97
7.1.260.0160.00815.96
7.1.250.0160.00815.94
7.1.240.0180.00816.39
7.1.230.0180.00716.39
7.1.220.0170.00716.41
7.1.210.0170.00716.41
7.1.200.0170.00716.41
7.1.190.0160.00816.42
7.1.180.0170.00716.36
7.1.170.0180.00716.37
7.1.160.0170.00716.36
7.1.150.0170.00816.36
7.1.140.0180.00816.38
7.1.130.0180.00716.37
7.1.120.0180.00816.35
7.1.110.0180.00716.48
7.1.100.0170.00716.40
7.1.90.0170.00716.38
7.1.80.0160.00816.41
7.1.70.0170.00716.30
7.1.60.0170.00716.41
7.1.50.0160.00816.42
7.1.40.0170.00716.43
7.1.30.0170.00716.43
7.1.20.0170.00816.40
7.1.10.0160.00816.39
7.1.00.0170.00716.39

preferences:
30.91 ms | 403 KiB | 5 Q