Closed wbartels closed 3 years ago
I'm not sure why that would give a speed improvement? In fact, I ran a quick test:
$starttime = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
hash('md5', random_bytes(32));
//md5(random_bytes(32));
}
echo number_format(microtime(true) - $starttime, 6);
And got timings, averaged across 5 runs:
md5
1.156 (1.186068, 1.129065, 1.185068, 1.152066, 1.128064)
hash
1.319 (1.327076, 1.307075, 1.323076, 1.329076, 1.308074)
So in my test hash
is 14% slower than md5
.
Sorry, you are right.
Al md5($data) functions can be replaced by hash('md5', $data). The hash() function is supported since PHP 5.12.