B
      \ถ	  ใ               @   s~   d dl mZ d dlZd dlmZ d dlmZm	Z	m
Z
 d dlmZ dd Zdd Zd	d
 ZG dd dejZedkrze ก  dS )้    )ฺprint_functionN)ฺcompilerฺtypesฺutils)ฺregistryc             C   s   | S )Nฉ )ฺxr   r   ๚7lib/python3.7/site-packages/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 )Nr   )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.
        iA  c                  s   t   d S )N)r
   r   )r   r   r	   ฺpython#   s    z)TestWrapper.test_overhead.<locals>.pythonc                  s     d S )Nr   r   )ฺcfuncr   r   r	   ฺpycfunc&   s    z*TestWrapper.test_overhead.<locals>.pycfuncc                  s     d S )Nr   r   )ฺdispr   r   r	   ฺ
overloaded)   s    z-TestWrapper.test_overhead.<locals>.overloadedg      เ?)ฺmaxsecN)r   ฺcompile_isolatedr
   r   ฺint32ฺentry_pointr   ฺCPUDispatcherฺadd_overloadฺprintr   ฺ	benchmark)ฺselfฺ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 )N)r   r   )r   r   r	   r   ?   s    z/TestWrapper.test_array_overhead.<locals>.pythonc                  s     d S )Nr   r   )r   r   r   r	   r   B   s    z0TestWrapper.test_array_overhead.<locals>.pycfuncc                  s     d S )Nr   r   )r   r   r   r	   r   E   s    z3TestWrapper.test_array_overhead.<locals>.overloadedg      เ?)r   )r   r   r   r   r   r   r   r   r   ZassertEqualZ	signatureฺargsZlayoutฺnpZzerosr   r   r   )r   r   r   r   r   r   )r   r   r   r	   ฺtest_array_overhead1   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
        iA  c                  s   t   d S )N)r   r   )r   r   r	   r   Z   s    z$TestWrapper.test_add.<locals>.pythonc                  s     d S )Nr   r   )r   r   r   r	   r   ]   s    z%TestWrapper.test_add.<locals>.pycfuncc                  s     d S )Nr   r   )r   r   r   r	   r   `   s    z(TestWrapper.test_add.<locals>.overloadedg      เ?)r   N)r   r   r   r   r   r   r   r   r   r   r   r   )r   r   r   r   r   r   )r   r   r   r	   ฺtest_addN   s    

zTestWrapper.test_addN)ฺ__name__ฺ
__module__ฺ__qualname__r   r$   r%   r   r   r   r	   r      s   r   ฺ__main__)Z
__future__r   Znumpyr#   Znumba.unittest_supportZunittest_supportZunittestZnumbar   r   r   Znumba.targetsr   r
   r   r   ZTestCaser   r&   ฺmainr   r   r   r	   ฺ<module>   s   S