o
    kis                     @   sd   d Z ddlZddlZddlZddlZddlm  mZ G dd dZ	d	ddZ
edkr0e
  dS dS )
zAExample of Timer and Compare APIs:

$ python -m examples.compare
    Nc                   @   sB   e Zd ZdZdddZdd Zdd	 Zd
d Zdd Zdd Z	dS )	FauxTorchzEmulate different versions of pytorch.

    In normal circumstances this would be done with multiple processes
    writing serialized measurements, but this simplifies that model to
    make the example clearer.
    returnNc                 C   s   || _ || _d S N)_real_torch_extra_ns_per_element)self
real_torchextra_ns_per_element r
   p/var/www/addictedbytheproject.nl/epg/venv/lib/python3.10/site-packages/torch/utils/benchmark/examples/compare.py__init__   s   
zFauxTorch.__init__c                 C   s,   t | }|dkrt|| j d  |S )Ni  g&.>)intnumeltimesleepr   )r   resultr   r
   r
   r   extra_overhead   s   zFauxTorch.extra_overheadc                 O      |  | jj|i |S r   )r   r   addr   argskwargsr
   r
   r   r   #      zFauxTorch.addc                 O   r   r   )r   r   mulr   r
   r
   r   r   &   r   zFauxTorch.mulc                 O   r   r   )r   r   catr   r
   r
   r   r   )   r   zFauxTorch.catc                 O   r   r   )r   r   matmulr   r
   r
   r   r   ,   r   zFauxTorch.matmulr   N)
__name__
__module____qualname____doc__r   r   r   r   r   r   r
   r
   r
   r   r      s    
r   r   c                     s   ddg g } d} fdddD }t || D ]'\}}| t|jdd td	|d
  dt||  dd tj	  qt  t
dd | D }td |  td |  |  |  d S )N)r   r   ztorch.add(x, y))r   zadd (extra +0)ztorch.add(x, y + zero)   c                    s   g | ]>\}} D ]7\}}}d D ]/}dD ]*}t j||dkrtntt|t|dftdtdd||d| ||dqqqqS ))   
   d   i  i'  iP  )r"      masterr%   r
   )torchxyzerozsize: )stmtglobalslabel	sub_labeldescriptionenvnum_threads)benchmark_utilsTimerr'   r   oneszeros).0branchoverhead_nsr-   r.   r+   sizer1   tasksr
   r   
<listcomp>8   s2    zmain.<locals>.<listcomp>))r&   N)	my_branchr"   )severe_regression   g?)min_run_timer"   z /  )endc                 S   s   g | ]}t |qS r
   )pickleloads)r6   ir
   r
   r   r<   U   s    
z== Unformatted ================================================================================
///////////////////////////////////////////////////////////////////////////////////////////////
z== Formatted ================================================================================
/////////////////////////////////////////////////////////////////////////////////////////////
)	enumerateappendrD   dumpsblocked_autorangeprintlensysstdoutflushr2   Comparetrim_significant_figurescolorize)serialized_resultsrepeatstimersrF   timer
comparisonr
   r:   r   main0   s0   

$
rX   __main__r   )r    rD   rM   r   r'   torch.utils.benchmarkutils	benchmarkr2   r   rX   r   r
   r
   r
   r   <module>   s   
 2
