a ZÚß^ c@s<ddlZddlZddlZdd„Zdd„Zdd„Zdd „Zejd Zed vrte d eƒe d edƒe dedƒnðedkrÆe ejƒdkrÆddl Z e dejdƒe dejde e ejdƒƒnžedkre ejƒdkrddl Z e dejdƒe dejdƒnVeeeƒrLee eeƒdƒrLe eeƒZe dee eeƒƒne deƒe deƒz eƒWnReyÀe ƒe dƒe dƒe dƒe dƒe d ƒe d!ƒe ƒ‚Yn0eƒed"d#d$ed%d&d$ed'd(d$ed)d*d$ed+d,d$ed-d.d$ed/d0d$eeƒjd1d$ed2d3d$dS)4iNcCs tdƒ‚dS)Nzeek, creatorFunc not overridden)Z RuntimeError©rrú)/usr/lib64/python3.9/test/time_hashlib.pyÚ creatorFunc src Csfd|d}d|}t}t ¡}t|ƒD]}||ƒ ¡}q(t ¡}td||d|dt|ƒd|ƒdS)NéÙžisZú%2.2fÚsecondsÚxZbytes)rÚtimeÚ perf_counterÚrangeÚdigestÚprintÚlen) ÚscaleÚnameZ iterationsZlongStrZlocalCFÚstartÚfrÚendrrrÚtest_scaled_msg s  rcCs<t ¡}tdƒD] }tƒ}qt ¡}td||ddƒdS)Né Nrrz[20000 creations])rrr rr )rrZdrrrrÚ test_creates  rcCs@t ¡}tdƒD]}tƒ ¡}qt ¡}td||ddƒdS)Nrrrz[20000 "" digests])rrr rr r )rrrrrrrÚ test_zero s   ri)Z_md5Z_shazimport zcreatorFunc = z.newztesting speed of oldzlegacy interfaceÚ_hashlibizcreatorFunc = _hashlib.%siztesting speed of _hashlib.%sz+creatorFunc = lambda x=_hashlib.new : x(%r)z!testing speed of _hashlib.new(%r)Z__call__ztesting speed of hashlib.z*creatorFunc = lambda x=hashlib.new : x(%r)z testing speed of hashlib.new(%r)z8pass argument(s) naming the hash to run a speed test on:z6 '_md5' and '_sha' test the legacy builtin md5 and shaz= '_hashlib' 'openssl_hName' 'fast' tests the builtin _hashlibz6 '_hashlib' 'hName' tests builtin _hashlib.new(shaFOO)z> 'hName' tests the hashlib.hName() implementation if it existsz. otherwise it uses hashlib.new(hName).rz [huge data])r ri|)z [large data]i&z [medium data]i¨z[4*small data]iPz[3*small data]iÔz[2*small data]ijz [small data]z[digest_size data]i z [tiny data])ZsysrZhashlibrrrrZargvZhNameZexecr r rZgetattrZhasattrZ ValueErrorZ digest_sizerrrrZs\   "