Created
May 31, 2017 09:07
-
-
Save Clarence-pan/5f0c54f94234799f5236fa1c2405133f to your computer and use it in GitHub Desktop.
测试MD5的速度
This file contains 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 characters
<?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), | |
]); |
This file contains 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 characters
[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