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.130.0050.00417.87
8.4.120.0340.00817.36
8.4.110.0420.00917.67
8.4.100.0340.00817.59
8.4.90.0410.00717.58
8.4.80.0310.00717.65
8.4.70.0360.00717.46
8.4.60.0350.00717.57
8.4.50.0410.00717.53
8.4.40.0320.00817.45
8.4.30.0350.00617.40
8.4.20.0290.00717.43
8.4.10.0230.00818.11
8.3.250.0230.00616.49
8.3.240.0250.00616.48
8.3.230.0200.00516.53
8.3.220.0270.00716.35
8.3.210.0220.00616.43
8.3.200.0270.00616.43
8.3.190.0290.00716.52
8.3.180.0320.00516.41
8.3.170.0280.00516.45
8.3.160.0280.00716.54
8.3.150.0280.00616.53
8.3.140.0260.00616.53
8.3.130.0220.00816.33
8.3.120.0260.00616.48
8.3.110.0280.00516.55
8.3.100.0300.00820.30
8.3.90.0210.00821.27
8.3.80.0270.00717.32
8.3.70.0290.00717.37
8.3.60.0280.00918.88
8.3.50.0340.00817.53
8.3.40.0310.00818.39
8.3.30.0240.00618.31
8.3.20.0250.00518.35
8.3.10.0230.00718.36
8.3.00.0220.00618.36
8.2.290.0270.00916.51
8.2.280.0270.00916.49
8.2.270.0280.00716.44
8.2.260.0270.00716.52
8.2.250.0250.00716.46
8.2.240.0290.00516.39
8.2.230.0260.00616.38
8.2.220.0260.00716.44
8.2.210.0250.00817.39
8.2.200.0250.00817.40
8.2.190.0290.00617.37
8.2.180.0290.00717.40
8.2.170.0290.00818.54
8.2.160.0310.00819.20
8.2.150.0230.00819.75
8.2.140.0280.00819.39
8.2.130.0230.00822.67
8.2.120.0290.00918.41
8.2.110.0210.00719.82
8.2.100.0250.00618.44
8.2.90.0290.00618.41
8.2.80.0270.00918.36
8.2.70.0150.00547.45
8.2.60.0250.00623.00
8.2.50.0200.00922.09
8.2.40.0220.00521.73
8.2.30.0170.00520.90
8.2.20.0160.00621.37
8.2.10.0110.00619.62
8.2.00.0150.00620.49
8.1.330.0320.00916.16
8.1.320.0290.00716.03
8.1.310.0220.00716.24
8.1.300.0280.00716.10
8.1.290.0250.00617.16
8.1.280.0260.00717.22
8.1.270.0270.00618.14
8.1.260.0250.00818.11
8.1.250.0300.00618.13
8.1.240.0240.00918.36
8.1.230.0280.00618.13
8.1.220.0280.00518.14
8.1.210.0280.01018.00
8.1.200.0240.00722.20
8.1.190.0190.00722.77
8.1.180.0200.00322.14
8.1.170.0190.00521.98
8.1.160.0190.00621.68
8.1.150.0190.00721.61
8.1.140.0130.00520.04
8.1.130.0160.00720.47
8.1.120.0160.00620.22
8.1.110.0150.00619.84
8.1.100.0130.00619.32
8.1.90.0140.00519.34
8.1.80.0140.00519.30
8.1.70.0100.00618.59
8.1.60.0140.00518.94
8.1.50.0150.00618.97
8.1.40.0150.00619.03
8.1.30.0150.00518.93
8.1.20.0150.00518.72
8.1.10.0140.00518.53
8.1.00.0160.00518.63
8.0.300.0280.00619.75
8.0.290.0250.00622.43
8.0.280.0210.00621.33
8.0.270.0190.00720.71
8.0.260.0190.00520.16
8.0.250.0160.00519.75
8.0.240.0150.00519.56
8.0.230.0120.00719.00
8.0.220.0150.00518.97
8.0.210.0130.00618.81
8.0.200.0140.00518.73
8.0.190.0140.00518.62
8.0.180.0130.00518.47
8.0.170.0130.00718.50
8.0.160.0130.00518.18
8.0.150.0140.00518.06
8.0.140.0140.00517.94
8.0.130.0140.00618.00
8.0.120.0120.00517.16
8.0.110.0120.00517.75
8.0.100.0120.00517.73
8.0.90.0120.00517.69
8.0.80.0120.00617.56
8.0.70.0120.00617.63
8.0.60.0120.00617.65
8.0.50.0120.00517.66
8.0.30.0120.00617.40
8.0.20.0130.00617.49
8.0.10.0120.00717.46
8.0.00.0120.00617.47
7.4.330.0150.00519.17
7.4.320.0170.00419.08
7.4.300.0120.00418.19
7.4.290.0120.00517.91
7.4.280.0120.00517.65
7.4.270.0120.00517.46
7.4.260.0140.00517.61
7.4.250.0130.00517.20
7.4.240.0120.00517.45
7.4.230.0120.00517.40
7.4.220.0100.00517.32
7.4.210.0100.00517.32
7.4.200.0110.00517.35
7.4.190.0110.00517.43
7.4.180.0100.00617.42
7.4.160.0110.00617.20
7.4.150.0110.00617.11
7.4.140.0110.00617.12
7.4.130.0110.00717.08
7.4.120.0110.00617.07
7.4.110.0110.00716.97
7.4.100.0110.00717.02
7.4.90.0110.00716.96
7.4.80.0120.00716.91
7.4.70.0110.00716.91
7.4.60.0110.00716.88
7.4.50.0110.00816.76
7.4.40.0110.00716.76
7.4.30.0110.00716.79
7.4.20.0100.00716.75
7.4.10.0110.00716.73
7.4.00.0100.00716.71
7.3.330.0140.00517.41
7.3.320.0140.00517.29
7.3.310.0140.00517.37
7.3.300.0140.00417.30
7.3.290.0110.00517.05
7.3.280.0120.00617.07
7.3.270.0120.00616.91
7.3.260.0130.00616.91
7.3.250.0120.00616.88
7.3.240.0120.00616.87
7.3.230.0120.00716.84
7.3.220.0130.00716.81
7.3.210.0120.00716.81
7.3.200.0130.00716.77
7.3.190.0120.00716.76
7.3.180.0120.00716.75
7.3.170.0120.00716.72
7.3.160.0120.00716.73
7.3.150.0120.00716.71
7.3.140.0120.00716.69
7.3.130.0120.00716.67
7.3.120.0110.00716.56
7.3.110.0110.00816.48
7.3.100.0110.00716.31
7.3.90.0120.00816.37
7.3.80.0120.00716.26
7.3.70.0120.00716.28
7.3.60.0100.00816.32
7.3.50.0120.00716.29
7.3.40.0110.00716.30
7.3.30.0110.00816.29
7.3.20.0130.00816.79
7.3.10.0140.00716.74
7.3.00.0140.00816.75
7.2.340.0160.00716.94
7.2.330.0160.00716.88
7.2.320.0160.00716.87
7.2.310.0150.00716.81
7.2.300.0150.00816.84
7.2.290.0150.00816.80
7.2.280.0150.00816.80
7.2.270.0150.00816.77
7.2.260.0140.00816.76
7.2.250.0140.00816.72
7.2.240.0140.00816.64
7.2.230.0140.00816.51
7.2.220.0140.00816.42
7.2.210.0140.00816.39
7.2.200.0130.00816.45
7.2.190.0130.00816.41
7.2.180.0130.00816.40
7.2.170.0130.00816.44
7.2.160.0120.00816.43
7.2.150.0140.00816.96
7.2.140.0140.00816.95
7.2.130.0150.00817.03
7.2.120.0140.00816.98
7.2.110.0140.00816.98
7.2.100.0150.00816.98
7.2.90.0150.00816.95
7.2.80.0150.00816.95
7.2.70.0140.00916.96
7.2.60.0140.00816.96
7.2.50.0150.00816.96
7.2.40.0150.00816.98
7.2.30.0150.00816.99
7.2.20.0150.00916.98
7.2.10.0160.00816.98
7.2.00.0150.00817.01
7.1.330.0170.00816.29
7.1.320.0160.00816.05
7.1.310.0160.00816.03
7.1.300.0160.00815.99
7.1.290.0160.00815.98
7.1.280.0170.00815.99
7.1.270.0160.00715.98
7.1.260.0150.00815.97
7.1.250.0160.00815.95
7.1.240.0180.00816.40
7.1.230.0180.00716.41
7.1.220.0170.00716.43
7.1.210.0170.00716.43
7.1.200.0170.00716.42
7.1.190.0160.00816.43
7.1.180.0170.00716.38
7.1.170.0170.00716.38
7.1.160.0170.00716.38
7.1.150.0170.00816.38
7.1.140.0170.00816.40
7.1.130.0170.00716.38
7.1.120.0180.00816.37
7.1.110.0180.00716.49
7.1.100.0170.00716.41
7.1.90.0170.00716.40
7.1.80.0160.00816.43
7.1.70.0170.00716.32
7.1.60.0170.00716.43
7.1.50.0160.00816.43
7.1.40.0170.00716.44
7.1.30.0170.00716.44
7.1.20.0170.00816.42
7.1.10.0160.00816.41
7.1.00.0170.00716.40

preferences:
30.77 ms | 403 KiB | 5 Q