B
    [                 @   sz   d Z ddlmZmZ ddlZddlZddlmZ ddddgZd	d
ddgZ	dddZ
dd Ze adadddZdd ZdS )zMSimple tools for timing functions' execution, when IPython is not available.     )print_functiondivisionN)rangeg      ?g     @@g    .Ag    eAsZmsu   μsnspassc       	      C   s   t j| |d}d\}}x@tddD ]2}| |dkr8P q"|dk	rL||krLP q"|d9 }q"W t|||| }|dkrtttt|d  d}nd}|||t	|  t
| fS )	z1Adaptively measure execution time of a function. )setup)      r
   
   g?Ng        r	   )timeitZTimerr   minrepeatintmathZfloorZlog10_scales_units)	funcr   limitZtimerr   Znumberitimeorder r   8lib/python3.7/site-packages/sympy/utilities/timeutils.pytimed   s    "r   c              C   s0   dd l } | dd}dd |dD }t|S )Nr   ZSYMPY_TIMINGS c             S   s   g | ]}|  qS r   )strip).0xr   r   r   
<listcomp>*   s    z __do_timings.<locals>.<listcomp>,)osgetenvsplitset)r!   Zresr   r   r   __do_timings'   s    r%   r
   c             C   sH   t d| d| d | d | d f  x| d D ]}t||d  q.W d S )N-z	%.2f %s%s   r   r	   r
   )print_print_timestack)stacklevelr   r   r   r   r)   1   s    $r)   c                s    fdd}|S )Nc                s   t kr S  fdd}|S )Nc                 sl   ddl m } t} jg d| ga| } | |}| }|| td< |d k	r\|d t |antt d a|S )Nr   )r   r'   r
   )r   
_timestackZ	func_nameappendr)   )argskwargsr   ZoldtimestackZt1rZt2)r   r   r   wrapper=   s    
z,timethis.<locals>.decorator.<locals>.wrapper)_do_timings)r   r1   )name)r   r   	decorator8   s    ztimethis.<locals>.decoratorr   )r3   r4   r   )r3   r   timethis7   s    r5   )r   N)r
   )__doc__Z
__future__r   r   r   r   Zsympy.core.compatibilityr   r   r   r   r%   r2   r,   r)   r5   r   r   r   r   <module>   s   

