Last active
August 29, 2015 14:23
Revisions
-
masakielastic revised this gist
Jun 28, 2015 . 1 changed file with 19 additions and 18 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,21 +13,22 @@ function timer(callable $block) { $buf = ''; $tests = [ 'random_bytes' => timer(function() { $buf = random_bytes(32); }), 'openssl_random_pseudo_bytes' => timer(function() { $buf = openssl_random_pseudo_bytes(32); }), 'mcrypt_create_iv' => timer(function() { $buf = mcrypt_create_iv(32, MCRYPT_DEV_URANDOM); }), 'mt_rand' => timer(function() { $buf = ''; for ($i = 0; $i < 32; ++$i) { $buf .= chr(mt_rand(0, 255)); } }) ]; var_dump($tests); -
masakielastic renamed this gist
Jun 27, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
masakielastic renamed this gist
Jun 27, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
masakielastic renamed this gist
Jun 27, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
masakielastic renamed this gist
Jun 27, 2015 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
masakielastic created this gist
Jun 27, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,33 @@ <?php function timer(callable $block) { $start = microtime(true); for ($i = 0; $i < 100000; ++$i) { $block(); } $end = microtime(true); return $end - $start; } $buf = ''; $tests['random_bytes'] = timer(function() { $buf = random_bytes(32); }); $tests['openssl_random_pseudo_bytes'] = timer(function() { $buf = openssl_random_pseudo_bytes(32); }); $tests['mcrypt_create_iv'] = timer(function() { $buf = mcrypt_create_iv(32, MCRYPT_DEV_URANDOM); }); $tests['mt_rand'] = timer(function() { $buf = ''; for ($i = 0; $i < 32; ++$i) { $buf .= chr(mt_rand(0, 255)); } }); This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ array(4) { ["random_bytes"]=> float(0.038606882095337) ["openssl_random_pseudo_bytes"]=> float(0.26424193382263) ["mcrypt_create_iv"]=> float(0.42767190933228) ["mt_rand"]=> float(0.79697513580322) }