f _ @s<ddlZddlZddlZddZddZddZdd Zejd Zed vrte d ee d ede dednedkre ejdkrddl Z e dejde dejde e ejdnedkre ejdkrddl Z e dejde dejdnVeeerLee eedrLe eeZe dee eene dee dez eWnReye e de de de de d e d!e Yn0eed"d#d$ed%d&d$ed'd(d$ed)d*d$ed+d,d$ed-d.d$ed/d0d$eejd1d$ed2d3d$dS)4NcCs tddS)Nzeek, creatorFunc not overridden) RuntimeErrorrr*/usr/lib64/python3.10/test/time_hashlib.py creatorFunc src Csfd|d}d|}t}t}t|D]}||}q(t}td||d|dt|d|dS)NٞZ%2.2fsecondsxbytes)rtime perf_counterrangedigestprintlen) scalenameZ iterationsZlongStrZlocalCFstartfr endrrrtest_scaled_msg s  rcCs<t}tdD] }t}qt}td||dddS)N Nr r z[20000 creations])r rrrr)rrdrrrr test_creates  rcCs@t}tdD]}t}qt}td||dddS)Nrr r z[20000 "" digests])r rrrrr)rrr rrrr test_zero s   r)Z_md5Z_shazimport zcreatorFunc = z.newztesting speed of oldzlegacy interface_hashlibzcreatorFunc = _hashlib.%sztesting speed of _hashlib.%sz+creatorFunc = lambda x=_hashlib.new : x(%r)z!testing speed of _hashlib.new(%r)__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])rri|)z [large data]i&z [medium data]iz[4*small data]iPz[3*small data]z[2*small data]jz [small data]z[digest_size data] z [tiny data])sysr ZhashlibrrrrargvZhNameexecrrrgetattrhasattr ValueError digest_sizerrrrs\   "