Skip to content

Instantly share code, notes, and snippets.

@Clarence-pan
Created May 31, 2017 09:07
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 Clarence-pan/5f0c54f94234799f5236fa1c2405133f to your computer and use it in GitHub Desktop.
Save Clarence-pan/5f0c54f94234799f5236fa1c2405133f to your computer and use it in GitHub Desktop.
测试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