便便代码人生

关注技术, 偶尔动动手

[原]php版md5,sha-1哪个更快

Posted by bianbian on 2007-03-16 08:01

本文Tags: , ,

一般随机密码都是rand()出来的,我就偷懒直接拿md5,sha-1这些函数来算了:

  1. $s = microtime(true);
  2. for($i = 0; $i < 100000; $i++)
  3.     getRandomPassword();
  4. echo microtime(true) - $s;
  5.  
  6. function getRandomPassword()
  7. {
  8.     ///除去substr和rand的版本:
  9.     //md5(microtime();
  10.     return substr(md5(microtime()), rand(0, 20), 8);
  11. }

经过测试,md5比sha1快(废话 - -):

function with substr and rand only function
md5 1.94637799263 1.79774594307
sha-1 2.12755990028 1.97592806816
标签: , ,

遵守创作共用协议,转载请链接形式注明来自http://bianbian.org 做人要厚道

相关日志

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>

(required)