o
    wZhc                     @   sb   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 Z
edkr/e
  dS dS )zAExample of Timer and Compare APIs:

$ python -m examples.compare
    Nc                   @   s@   e Zd ZdZ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.
    c                 C   s   || _ || _d S N)_real_torch_extra_ns_per_element)selfZ
real_torchZextra_ns_per_element r   U/var/www/auris/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.matmulN)
__name__
__module____qualname____doc__r	   r   r   r   r   r   r   r   r   r   r      s    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   ZonesZzeros).0branchZoverhead_nsr)   r*   r'   sizer-   tasksr   r   
<listcomp>8   s2    zmain.<locals>.<listcomp>))r"   N)Z	my_branchr   )Zsevere_regression   g?)Zmin_run_timer   z /  )endc                 S   s   g | ]}t |qS r   )pickleloads)r0   ir   r   r   r5   U   s    
z== Unformatted ================================================================================
///////////////////////////////////////////////////////////////////////////////////////////////
z== Formatted ================================================================================
/////////////////////////////////////////////////////////////////////////////////////////////
)	enumerateappendr:   dumpsZblocked_autorangeprintlensysstdoutflushr.   CompareZtrim_significant_figuresZcolorize)Zserialized_resultsZrepeatsZtimersr<   timerZ
comparisonr   r3   r   main0   s0   

$
rG   __main__)r   r:   rB   r   r#   Ztorch.utils.benchmarkutilsZ	benchmarkr.   r   rG   r   r   r   r   r   <module>   s    2
