U
    ,da	                     @   sf   d dl Zd dlZd dlmZmZmZmZ dd Zdd Z	dd Z
G d	d
 d
ejZedkrbe  dS )    N)typesutilscompilerregistryc                 C   s   | S N xr   r   </tmp/pip-unpacked-wheel-eu7e0c37/numba/tests/test_wrapper.pyoverhead   s    r   c                 C   s   d| d< d| d< d S )N   r      r   r   r   r   r
   array_overhead   s    r   c                 C   s   | |  |  |  |  S r   r   r   r   r   r
   add   s    r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )TestWrapperc                    s   t ttjg}|j tt| dfdd} fdd}fdd}t	t t	t
j|dd	 t	t
j|dd	 t	t
j|dd	 d
S )zW
        This will show higher overhead due to unboxing in the native version.
        A  c                      s   t   d S r   )r   r   r   r   r
   python    s    z)TestWrapper.test_overhead.<locals>.pythonc                      s     d S r   r   r   cfuncr	   r   r
   pycfunc#   s    z*TestWrapper.test_overhead.<locals>.pycfuncc                      s     d S r   r   r   dispr	   r   r
   
overloaded&   s    z-TestWrapper.test_overhead.<locals>.overloaded      ?ZmaxsecN)r   compile_isolatedr   r   int32entry_pointr   CPUDispatcheradd_overloadprintr   	benchmarkselfZcrr   r   r   r   r   r   r	   r
   test_overhead   s    

zTestWrapper.test_overheadc                    s   t ttjddd g}|j tt| | 	|j
jd jd tjdddfdd	} fd
d}fdd}tt ttj|dd ttj|dd ttj|dd dS )z
        The time to set two array element seems to be more expensive than
        the overhead of the overloaded call.
        Nr   r   Cr   r   )shapeZdtypec                      s   t   d S r   )r   r   r   r   r
   r   <   s    z/TestWrapper.test_array_overhead.<locals>.pythonc                      s     d S r   r   r   r   r   r
   r   ?   s    z0TestWrapper.test_array_overhead.<locals>.pycfuncc                      s     d S r   r   r   r   r   r
   r   B   s    z3TestWrapper.test_array_overhead.<locals>.overloadedr   r   )r   r   r   r   r   r   r   r   r   assertEqual	signatureargsZlayoutnpzerosr    r   r!   r"   r   r$   r
   test_array_overhead.   s    

zTestWrapper.test_array_overheadc                    s   t ttjg}|j tt| dfdd} fdd}fdd}t	t t	t
j|dd	 t	t
j|dd	 t	t
j|dd	 d
S )zu
        This seems to be about the amount of work to balance out the overhead
        by the overloaded one
        r   c                      s   t   d S r   )r   r   r   r   r
   r   W   s    z$TestWrapper.test_add.<locals>.pythonc                      s     d S r   r   r   r   r   r
   r   Z   s    z%TestWrapper.test_add.<locals>.pycfuncc                      s     d S r   r   r   r   r   r
   r   ]   s    z(TestWrapper.test_add.<locals>.overloadedr   r   N)r   r   r   r   r   r   r   r   r   r    r   r!   r"   r   r$   r
   test_addK   s    

zTestWrapper.test_addN)__name__
__module____qualname__r%   r-   r.   r   r   r   r
   r      s   r   __main__)Znumpyr+   ZunittestZ
numba.corer   r   r   r   r   r   r   ZTestCaser   r/   mainr   r   r   r
   <module>   s   S