3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Generate a random string, using a cryptographically secure * pseudorandom number generator (random_int) * * per https://stackoverflow.com/a/31107425 */ function get_random_string($length = 16, $keyspace = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ') { $str = ''; $max = mb_strlen($keyspace, '8bit') - 1; for ($i = 0; $i < $length; ++$i) { $str .= $keyspace[random_int(0, $max)]; } return $str; } // Tests. echo 'Test 01: ' . get_random_string() . "\n"; echo 'Test 02: ' . get_random_string(2) . "\n"; echo 'Test 03: ' . get_random_string(32) . "\n"; echo 'Test 04: ' . get_random_string(16, '1234567') . "\n"; echo 'Test 05: ' . get_random_string(16, '123abcABC') . "\n"; echo 'Test 06: ' . get_random_string(16, 'ABC') . "\n"; echo 'Test 07: ' . get_random_string(16, '10') . "\n";

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.00.0030.01015.18
7.3.120.0040.01515.07
7.3.110.0030.01415.15
7.3.100.0090.00614.59
7.3.90.0060.00614.50
7.3.80.0070.00714.69
7.3.70.0080.00414.73
7.3.60.0070.00714.70
7.3.50.0030.00714.88
7.3.40.0040.01114.95
7.3.30.0030.00914.85
7.3.20.0060.00616.64
7.3.10.0070.00716.35
7.3.00.0160.00016.46
7.2.250.0090.00915.00
7.2.240.0130.00714.91
7.2.230.0050.00514.91
7.2.220.0060.00915.31
7.2.210.0000.01615.18
7.2.200.0030.01015.03
7.2.190.0000.01415.21
7.2.180.0030.00615.07
7.2.170.0090.00615.07
7.2.90.3720.00714.73
7.2.80.3750.01014.59
7.2.70.3770.01315.05
7.2.60.4070.00614.75
7.2.50.4040.01614.75
7.2.40.2680.00715.11
7.2.30.3570.01014.96
7.2.20.4110.01014.67
7.2.10.4780.01014.98
7.2.00.4070.01015.12
7.1.330.0100.00715.86
7.1.320.0030.01015.95
7.1.310.0030.01415.82
7.1.300.0100.00615.62
7.1.290.0100.00316.01
7.1.280.0030.01015.65
7.1.270.0060.00915.77
7.1.260.0080.00815.67
7.1.210.5470.01013.63
7.1.200.4760.01013.91
7.1.190.3530.00913.93
7.1.180.3990.01613.84
7.1.170.4120.01213.53
7.1.160.1180.01613.84
7.1.150.3690.00713.75
7.1.140.4370.00713.98
7.1.130.3640.01313.61
7.1.120.3810.00713.52
7.1.110.2920.01013.66
7.1.100.0220.00013.92
7.1.90.0040.01413.85
7.1.80.0220.00613.90
7.1.70.1210.01214.05
7.1.60.1470.00631.73
7.1.50.0270.01031.84
7.1.40.1260.01031.61
7.1.30.0250.01431.83
7.1.20.1590.00931.72
7.1.10.0550.01513.62
7.1.00.1030.00313.93

preferences:
36.93 ms | 401 KiB | 5 Q