1

this code is obtuse for my test?

error_reporting(E_ALL);
ini_set('display_errors', 1);

$p = 'abc';
$i = microtime(1);
echo hash('SHA256', $p);
echo '<hr />';
var_dump(number_format(microtime(1) - $i, 7));
echo '<hr />';

$i = microtime(1);
echo hash('SHA512', $p);
echo '<hr />';
var_dump(number_format(microtime(1) - $i, 7));
echo '<hr />';

why forever I get a fragment of time in the SECOND line vs the first?

is more efficient SHA512 or my "BENCHMARK" is ridiculous ?

Stackoverflow
  • 449
  • 5
  • 13
  • [SHA-512 faster than SHA-256?](https://crypto.stackexchange.com/q/26336). Also, presumably the first call to `hash` will warm things up (CPU frequency and stuff associated with interpreting the `hash()` function), so check if you still get the same results with the tests in the other order: [Idiomatic way of performance evaluation?](https://stackoverflow.com/q/60291987). If not, then your methodology is broken and whichever you test first is just slower because of warm-up effects. – Peter Cordes Apr 12 '21 at 00:16
  • Other google results include https://news.ycombinator.com/item?id=13546354 - this is a well-known phenomenon on CPUs (especially 64-bit CPUs) without special hardware acceleration for SHA256 (or SHA512). – Peter Cordes Apr 12 '21 at 00:39

0 Answers0