3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * Generate a PBKDF2 key derivation of a supplied password * * This is a hash_pbkdf2() implementation for PHP versions 5.3 and 5.4. * @link http://www.php.net/manual/en/function.hash-pbkdf2.php * * @param string $algo * @param string $password * @param string $salt * @param int $iterations * @param int $length * @param bool $rawOutput * * @return string */ function compat_pbkdf2($algo, $password, $salt, $iterations, $length = 0, $rawOutput = false) { // check for hashing algorithm if (!in_array(strtolower($algo), hash_algos())) { trigger_error(sprintf( '%s(): Unknown hashing algorithm: %s', __FUNCTION__, $algo ), E_USER_WARNING); return false; } // check for type of iterations and length foreach (array(4 => $iterations, 5 => $length) as $index => $value) { if (!is_numeric($value)) { trigger_error(sprintf( '%s() expects parameter %d to be long, %s given', __FUNCTION__, $index, gettype($value) ), E_USER_WARNING); return null; } } // check iterations $iterations = (int)$iterations; if ($iterations <= 0) { trigger_error(sprintf( '%s(): Iterations must be a positive integer: %d', __FUNCTION__, $iterations ), E_USER_WARNING); return false; } // check length $length = (int)$length; if ($length < 0) { trigger_error(sprintf( '%s(): Iterations must be greater than or equal to 0: %d', __FUNCTION__, $length ), E_USER_WARNING); return false; } // check salt if (strlen($salt) > PHP_INT_MAX - 4) { trigger_error(sprintf( '%s(): Supplied salt is too long, max of INT_MAX - 4 bytes: %d supplied', __FUNCTION__, strlen($salt) ), E_USER_WARNING); return false; } // initialize $derivedKey = ''; $loops = 1; if ($length > 0) { $loops = (int)ceil($length / strlen(hash($algo, '', $rawOutput))); } // hash for each blocks for ($i = 1; $i <= $loops; $i++) { $digest = hash_hmac($algo, $salt . pack('N', $i), $password, true); $block = $digest; for ($j = 1; $j < $iterations; $j++) { $digest = hash_hmac($algo, $digest, $password, true); $block ^= $digest; } $derivedKey .= $block; } if (!$rawOutput) { $derivedKey = bin2hex($derivedKey); } if ($length > 0) { return substr($derivedKey, 0, $length); } return $derivedKey; } // test echo hash_pbkdf2("sha256", "!Password@123#", 'pCtRL7cHbJR-6Px1g5(&o&O(2Kj_pdbC', 1000, 64); echo compat_pbkdf2("sha256", "!Password@123#", 'pCtRL7cHbJR-6Px1g5(&o&O(2Kj_pdbC', 1000, 64);

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.3.60.0060.01318.28
8.3.50.0140.01018.30
8.3.40.0100.01018.92
8.3.30.0070.01519.02
8.3.20.0030.00721.93
8.3.10.0070.00322.02
8.3.00.0100.00019.93
8.2.180.0140.01116.88
8.2.170.0130.00622.96
8.2.160.0070.01121.32
8.2.150.0030.00724.18
8.2.140.0070.00324.66
8.2.130.0070.00319.33
8.2.120.0030.00726.35
8.2.110.0060.00622.38
8.2.100.0120.00317.97
8.2.90.0040.00917.97
8.2.80.0040.00719.45
8.2.70.0060.00618.05
8.2.60.0080.00317.93
8.2.50.0050.00518.10
8.2.40.0110.00020.66
8.2.30.0000.01019.49
8.2.20.0000.01018.36
8.2.10.0040.00718.19
8.2.00.0070.00318.21
8.1.280.0100.01025.92
8.1.270.0040.00724.04
8.1.260.0030.00926.35
8.1.250.0000.01128.09
8.1.240.0000.01219.41
8.1.230.0110.00420.96
8.1.220.0090.00317.74
8.1.210.0040.00818.77
8.1.200.0030.01017.11
8.1.190.0070.00617.35
8.1.180.0040.00718.10
8.1.170.0030.01018.78
8.1.160.0030.00718.98
8.1.150.0030.00720.85
8.1.140.0040.00717.76
8.1.130.0000.01219.00
8.1.120.0030.01017.56
8.1.110.0040.00717.44
8.1.100.0000.01017.40
8.1.90.0030.00817.43
8.1.80.0090.00317.61
8.1.70.0030.00717.45
8.1.60.0110.00017.61
8.1.50.0040.00717.55
8.1.40.0040.00717.63
8.1.30.0040.00817.59
8.1.20.0040.00817.74
8.1.10.0040.00717.72
8.1.00.0000.01417.46
8.0.300.0080.00320.16
8.0.290.0080.00416.88
8.0.280.0070.00318.44
8.0.270.0070.00317.42
8.0.260.0030.00617.38
8.0.250.0040.00817.07
8.0.240.0000.01016.96
8.0.230.0000.01117.06
8.0.220.0030.00716.88
8.0.210.0000.01016.89
8.0.200.0030.00716.95
8.0.190.0030.00717.07
8.0.180.0030.00717.04
8.0.170.0000.01117.07
8.0.160.0000.01017.05
8.0.150.0070.00717.04
8.0.140.0000.01017.04
8.0.130.0040.00413.33
8.0.120.0000.01216.88
8.0.110.0070.00316.82
8.0.100.0070.00316.86
8.0.90.0070.00316.94
8.0.80.0120.00916.94
8.0.70.0040.00716.97
8.0.60.0000.01016.89
8.0.50.0070.00417.04
8.0.30.0120.01217.22
8.0.20.0030.01917.40
8.0.10.0070.00317.01
8.0.00.0050.01717.11
7.4.330.0000.00815.55
7.4.320.0000.01116.52
7.4.300.0000.01016.61
7.4.290.0000.01016.59
7.4.280.0000.01116.70
7.4.270.0000.01016.77
7.4.260.0030.00716.50
7.4.250.0030.00716.72
7.4.240.0030.00816.77
7.4.230.0000.01016.72
7.4.220.0060.00616.81
7.4.210.0080.01316.64
7.4.200.0040.00716.55
7.4.160.0110.01616.65
7.4.140.0130.01317.86
7.4.130.0030.01916.64
7.4.120.0120.01216.62
7.4.110.0070.01516.61
7.4.100.0070.01716.64
7.4.90.0030.01816.60
7.4.80.0060.02119.39
7.4.70.0070.01416.60
7.4.60.0060.01616.74
7.4.50.0060.01316.51
7.4.40.0030.01716.57
7.4.00.0090.01314.86
7.3.330.0040.00413.40
7.3.320.0070.00313.42
7.3.310.0000.01016.57
7.3.300.0040.00716.44
7.3.290.0050.00516.34
7.3.280.0070.01816.54
7.3.260.0090.01416.48
7.3.240.0080.01616.65
7.3.230.0100.01316.48
7.3.210.0090.01316.45
7.3.200.0090.01316.41
7.3.190.0060.01616.48
7.3.180.0120.01816.38
7.3.170.0100.01916.61
7.3.160.0060.01616.52
7.3.120.0130.01315.12
7.3.110.0030.01514.41
7.3.100.0000.02215.02
7.3.90.0030.01314.93
7.3.80.0100.01015.02
7.3.70.0120.00915.06
7.3.60.0000.01915.00
7.3.50.0070.01014.77
7.3.40.0060.01314.67
7.3.30.0000.02114.64
7.3.20.0040.01416.53
7.3.10.0000.01916.77
7.3.00.0090.00916.51
7.2.330.0150.01016.82
7.2.320.0130.01316.74
7.2.310.0150.00916.90
7.2.300.0090.01616.56
7.2.290.0110.01516.66
7.2.250.0070.01815.32
7.2.240.0000.02615.23
7.2.230.0030.01915.14
7.2.220.0110.00915.09
7.2.210.0000.01614.80
7.2.200.0070.01514.89
7.2.190.0110.01115.17
7.2.180.0100.01315.27
7.2.170.0100.01015.03
7.2.110.0070.01116.52
7.2.60.0030.01417.00
7.2.50.0000.01916.92
7.2.40.0820.01518.14
7.2.30.1410.02318.20
7.2.20.1150.01818.04
7.2.10.0740.01818.07
7.2.00.0910.02218.23
7.1.330.0060.01215.96
7.1.320.0070.01315.83
7.1.310.0030.01315.70
7.1.300.0000.02315.85
7.1.290.0090.00915.70
7.1.280.0000.01815.88
7.1.270.0080.00415.51
7.1.260.0030.01715.83
7.1.200.0030.01615.75
7.1.160.0830.01516.86
7.1.150.0850.01916.55
7.1.140.1060.02216.76
7.1.130.1590.02416.97
7.1.120.1210.01816.90
7.1.110.1250.01716.43
7.1.100.1480.02015.99
7.1.90.1420.01716.45
7.1.80.0920.01816.43
7.1.70.0820.01615.13
7.1.60.1230.02233.29
7.1.50.1240.02332.87
7.1.40.1190.03032.75
7.1.30.1440.01832.80
7.1.20.1150.01832.84
7.1.10.0870.01814.77
7.1.00.0970.01914.79

preferences:
58.63 ms | 401 KiB | 5 Q