import hashlib import time def mymd5(str): md5 = hashlib.md5() md5.update(msg) for i in range(loop): md5.hexdigest() def mysha1(str): sha = hashlib.sha1() sha.update(msg) for i in range(loop): sha.hexdigest() def mysha384(str): sha = hashlib.sha384() sha.update(msg) for i in range(loop): sha.hexdigest() def mysha512(str): sha = hashlib.sha512() sha.update(msg) for i in range(loop): sha.hexdigest() if __name__ == "__main__": #str = 'a' str = input('请输入要计算hash的文本:\n') msg = str.encode() loop = 10000000 print("文本:",str,",计算",loop,"次hash\n") start = time.time() mymd5(msg) print('md5耗时', time.time() - start, '\n') start = time.time() mysha1(msg) print('sha1耗时', time.time() - start, '\n') start = time.time() mysha384(msg) print('sha384耗时', time.time() - start, '\n') start = time.time() mysha512(msg) print('sha512耗时', time.time() - start, '\n')