[原]php版md5,sha-1哪个更快
Posted by bianbian on 2007-03-16 08:01
一般随机密码都是rand()出来的,我就偷懒直接拿md5,sha-1这些函数来算了:
- $s = microtime(true);
- for($i = 0; $i < 100000; $i++)
- getRandomPassword();
- echo microtime(true) - $s;
- function getRandomPassword()
- {
- ///除去substr和rand的版本:
- //md5(microtime();
- return substr(md5(microtime()), rand(0, 20), 8);
- }
经过测试,md5比sha1快(废话 - -):
| function | with substr and rand | only function |
|---|---|---|
| md5 | 1.94637799263 | 1.79774594307 |
| sha-1 | 2.12755990028 | 1.97592806816 |
遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道