Skip to content

Instantly share code, notes, and snippets.

@paragonie-scott
Created October 11, 2018 16:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paragonie-scott/d24b7d1757488e5e3276c75027227d27 to your computer and use it in GitHub Desktop.
Save paragonie-scott/d24b7d1757488e5e3276c75027227d27 to your computer and use it in GitHub Desktop.
<?php
define('BENCH_ROUNDS', 200);
$start = $stop = 0.0;
$salt = random_bytes(32);
$short = str_repeat("A", 16);
$medium = str_repeat("A", 65);
$long = str_repeat("A", 1 << 20);
$start = microtime(true);
for ($i = 0; $i < BENCH_ROUNDS; ++$i) {
hash_pbkdf2('sha256', $short, $salt, 10000);
}
$end = microtime(true);
echo BENCH_ROUNDS, ' rounds:', PHP_EOL;
echo "16 char password: ", number_format($end - $start, 3), " seconds.", PHP_EOL;
$start = microtime(true);
for ($i = 0; $i < BENCH_ROUNDS; ++$i) {
hash_pbkdf2('sha256', $medium, $salt, 10000);
}
$end = microtime(true);
echo "65 char password: ", number_format($end - $start, 3), " seconds.", PHP_EOL;
$start = microtime(true);
for ($i = 0; $i < BENCH_ROUNDS; ++$i) {
hash_pbkdf2('sha256', $long, $salt, 10000);
}
$end = microtime(true);
echo (1 << 20), " char password: ", number_format($end - $start, 3), " seconds.", PHP_EOL;
scott@paragonie-test:/mnt/share$ php pbkdf2bench.php
200 rounds:
16 char password: 5.972 seconds.
65 char password: 4.012 seconds.
1048576 char password: 5.315 seconds.
scott@paragonie-test:/mnt/share$ php pbkdf2bench.php
200 rounds:
16 char password: 4.190 seconds.
65 char password: 3.959 seconds.
1048576 char password: 6.240 seconds.
scott@paragonie-test:/mnt/share$ php pbkdf2bench.php
200 rounds:
16 char password: 5.096 seconds.
65 char password: 4.830 seconds.
1048576 char password: 7.638 seconds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment