a �DOg�4�@s�ddlZddlZddlZddlZgd�ZdZdZdZejZ e Z dZ dd�Z Gd d �d �Zd d e edfd d �Zd d e eedfdd�Zddd�dd�Zedkr�e�e��dS)�N)�Timer�timeit�repeat� default_timerz i@B�z� def inner(_it, _timer{init}): {setup} _t0 = _timer() for _i in _it: {stmt} _t1 = _timer() return _t1 - _t0 cCs|�ddd|�S)N� � )�replace)�src�indent�r �/usr/lib64/python3.9/timeit.py�reindentOsrc@sLeZdZddedfdd�Zd dd�Zefdd�Zeefd d �Z dd d �Z dS)r�passNc Cs�||_i}|durt�n|}d}t|t�rJt|td�|d}t|d�}n*t|�rl||d<|d7}d}d}ntd��t|t�r�t||td�t|d �}n&t|�r�||d <|d 7}d }ntd ��t j |||d�} | |_ t| td�} t | ||�|d|_ dS)N��execr��_setupz, _setup=_setupz_setup()z&setup is neither a string nor callable�Z_stmtz , _stmt=_stmtz_stmt()z%stmt is neither a string nor callable)�stmt�setup�init�inner)�timer�_globals� isinstance�str�compile�dummy_src_namer�callable� ValueError�template�formatr rr) �selfrrr�globalsZlocal_nsZ global_nsrZ stmtprefixr �coder r r �__init__es6       zTimer.__init__cCsJddl}ddl}|jdur:t|j�d|j�d�tf|jt<|j|d�dS)Nrr��file)� linecache� tracebackr �len�splitr�cache� print_exc)r#r(r)r*r r r r.�s  � zTimer.print_exccCsNt�d|�}t��}t��z|�||j�}W|rJt��n|rHt��0|S�N)� itertoolsr�gc� isenabled�disablerr�enable)r#�number�itZgcoldZtimingr r r r�s  � z Timer.timeitcCs*g}t|�D]}|�|�}|�|�q |Sr/)�ranger�append)r#rr5�r�i�tr r r r�s    z Timer.repeatcCsPd}dD]8}||}|�|�}|r,|||�|dkr||fSq|d9}qdS)N�)r<�rg�������?� )r)r#�callbackr:�jr5� time_takenr r r � autorange�s   zTimer.autorange)N)N) �__name__� __module__� __qualname__rr&r.�default_numberr�default_repeatrrBr r r r rSs� #  rrcCst||||��|�Sr/)rr)rrrr5r$r r r r�srcCst||||��||�Sr/)rr)rrrrr5r$r r r r�sr)� _wrap_timerc s�|durtjdd�}ddl}z|�|dgd��\}}Wn8|jyp}zt|�td�WYd}~dSd}~00t}d�|�p�d}d�g}t}d} d�d d d d d ��d�|D]�\} } | dvr�t| ��| dvr�|� | �| dv�r| �vr�| �ntdtj d�dS| dv�r$t| �}|dk�r$d}| dv�r4t j }| dv�rT| �rL�d7�| d7} | dvr�tt dd�dSq�d�|��p~d}ddl} tj�d| j�|du�r�||�}t|||�} �dk�r d}| �rևfdd�}z| �|�\�}Wn| ��YdS0| �r t�z| �|��}Wn| ��YdS0���fdd�}| �rhtdd�t||���t��fd d!�|D�}t|�}td"��dk�r�d#nd$|||�f�t|�}t|�}||d%k�r�ddl}|�d&||�||�ftd$d�dS)'Nr<rz n:u:s:r:tcpvh) znumber=zsetup=zrepeat=�timeZclock�process�verbosezunit=�helpz#use -h/--help for command line helpr=rrg��&� .>g�����ư>g����MbP?g�?)ZnsecZusecZmsecZsec�)z-nz--number)z-sz--setup)z-uz--unitz:Unrecognized unit. Please select nsec, usec, msec, or sec.r')z-rz--repeat)z-pz --process)z-vz --verbose)z-hz--helpr)�endcs.d}|dk}t|j||rdnd|�d��dS)Nz%{num} loop{s} -> {secs:.{prec}g} secsr<�sr)�numrOZsecsZprec)�printr")r5rA�msg�plural)� precisionr r r??s �zmain..callbackcs`�}|dur�|}n8dd����D�}|jdd�|D]\}}||kr8qNq8d�|||fS)NcSsg|]\}}||f�qSr r )�.0�unit�scaler r r � Y�z-main..format_time..T)�reversez%.*g %s)�items�sort)�dtrVrWZscales)rT� time_unit�unitsr r � format_timeSs   zmain..format_timez raw times: %sz, csg|] }|��qSr r )rUr])r5r r rXdrYzmain..z"%d loop%s, best of %d: %s per looprOrrztThe test results are likely unreliable. The worst time (%s) was more than four times slower than the best time (%s).)�sys�argv�getopt�errorrQr�joinrG�intr8�stderrrI� process_time�__doc__�os�path�insert�curdirrrBr.r�map�min�max�warnings� warn_explicit� UserWarning)�argsrHrcZopts�errrrrrrK�o�arjr;r?�_Z raw_timingsr`ZtimingsZbestZworstrqr )r5rTr^r_r �main�s��    �         ����ry�__main__)N)r1rarIr0�__all__rrFrG� perf_counterrr$rr!rrrrryrC�exitr r r r �4s. � �