Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
测试MD5的速度
<?php
$testRounds = 100;
$testTimes = 1000000;
$times = [];
$data = 'abcdefgh';
for ($i = 0; $i < $testRounds; $i++){
$begin = microtime(true);
for ($j = 0; $j < $testTimes; $j++){
$hash = md5($data);
}
$times[] = microtime(true) - $begin;
}
print_r([
'rounds' => $testRounds,
'times of a round' => $testTimes,
'avg' => array_sum($times) / count($times),
'max' => max($times),
'min' => min($times),
]);
[root@f4d5945f1d7c tools]# php speed-of-md5.php
Array
(
[rounds] => 100
[times of a round] => 1000000
[avg] => 0.23415904045105
[max] => 0.28906106948853
[min] => 0.21188998222351
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment