U
    ,]                     @   s  d Z ddlmZ ddlmZ dZdZedd\ZZ	Z
ZZG dd	 d	eZdZdZefd
dZefddZdaeadadadgd add tgd D adadaefddZdd Zdd Zdd Zdd Zdd Z dd  Z!d!d" Z"d#d$ Z#d%d& Z$d'd( Z%d)d* Z&e'd+krddl(Z(d,d- Z)e*e(j+d Z,e,dkrBe)d.e,  nLe,dkrze-e(j+d Z.W n( e/k
r   e)d/e(j+d   Y nX neZ.ee. dS )0a  
"PYSTONE" Benchmark Program

Version:        Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)

Author:         Reinhold P. Weicker,  CACM Vol 27, No 10, 10/84 pg. 1013.

                Translated from ADA to C by Rick Richardson.
                Every method to preserve ADA-likeness has been used,
                at the expense of C-ness.

                Translated from C to Python by Guido van Rossum.

Version History:

                Version 1.1 corrects two bugs in version 1.0:

                First, it leaked memory: in Proc1(), NextRecord ends
                up having a pointer to itself.  I have corrected this
                by zapping NextRecord.PtrComp at the end of Proc1().

                Second, Proc3() used the operator != to compare a
                record to None.  This is rather inefficient and not
                true to the intention of the original benchmark (where
                a pointer comparison to None is intended; the !=
                operator attempts to find a method __cmp__ to do value
                comparison of the record).  Version 1.1 runs 5-10
                percent faster than version 1.0, so benchmark figures
                of different versions can't be compared directly.

    )print_function)clockiP  z1.1      c                   @   s   e Zd ZdddZdd ZdS )RecordNr   c                 C   s"   || _ || _|| _|| _|| _d S N)PtrCompDiscrEnumCompIntComp
StringComp)selfr   r	   r
   r   r    r   ?/usr/lib/python3/dist-packages/future/backports/test/pystone.py__init__/   s
    zRecord.__init__c                 C   s   t | j| j| j| j| jS r   )r   r   r	   r
   r   r   )r   r   r   r   copy7   s     zRecord.copy)Nr   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   r   -   s
       
r   c                 C   s.   t | \}}tdt| |f  td|  d S )Nz#Pystone(%s) time for %d passes = %gz-This machine benchmarks at %g pystones/second)pystonesprint__version__)loops	benchtimeZstonesr   r   r   main>   s
    r   c                 C   s   t | S r   )Proc0)r   r   r   r   r   E   s    r    3   c                 C   s   g | ]}|d d  qS r   r   ).0xr   r   r   
<listcomp>M   s     r    Nc                 C   s^  t  }t| D ]}qt  | }t at att_tt_tt_	dt_
dt_d}dtd d< t  }t| D ]}t  t  d}d}d	}t}t|| a||k rd
| | }	t||}	|d }qttt||	 ttad}
|
tkr|t|
dkrtt}tt|
d }
q|| }	|	| }d|	|  | }t|}qft  | | }|dkrNd}n| | }||fS )N(   zDHRYSTONE PROGRAM, SOME STRINGzDHRYSTONE PROGRAM, 1'ST STRING
               zDHRYSTONE PROGRAM, 2'ND STRING   r   ACg        )r   ranger   
PtrGlbNextPtrGlbr   Ident1r	   Ident3r
   r   r   
Array2GlobProc5Proc4Ident2Func2BoolGlobProc7Proc8
Array1GlobProc1	Char2GlobFunc1Proc6chrordProc2)r   Z	starttimeiZnulltimeZ
String1LocZIntLoc1ZIntLoc2Z
String2LocEnumLocZIntLoc3Z	CharIndexr   ZloopsPerBenchtimer   r   r   r   Q   sT    






r   c                 C   sv   t   | _}d| _| j|_| j|_t|j|_|jtkrdd|_t| j|_t j|_t	|jd|_n| } d |_| S )Nr'   r   r"   )
r,   r   r   r   Proc3r	   r-   r;   r
   r5   )ZPtrParInZ
NextRecordr   r   r   r8      s    
r8   c                 C   s4   | d }t dkr$|d }|t } t}|tkrq0q| S )Nr"   r(   r   )	Char1GlobIntGlobr-   )ZIntParIOIntLocr@   r   r   r   r>      s    r>   c                 C   s$   t d k	rt j} ndatdtt _| S )Nd   r"   )r,   r   rC   r5   r   )Z	PtrParOutr   r   r   rA      s
    rA   c                  C   s   t dk} | pt} dad S )Nr(   B)rB   r4   r9   )ZBoolLocr   r   r   r1      s    r1   c                   C   s   da tad S )Nr(   )rB   FALSEr4   r   r   r   r   r0      s    r0   c                 C   sb   | }t | st}| tkrt}n@| tkr:tdkr4t}q^t}n$| tkrHt}n| tkrRn| tkr^t}|S )NrE   )Func3Ident4r-   r2   rC   r.   Ident5)	EnumParInZ
EnumParOutr   r   r   r;      s     r;   c                 C   s   | d }|| }|S )Nr%   r   )IntParI1IntParI2rD   Z	IntParOutr   r   r   r5      s    r5   c                 C   s   |d }|| |< | | | |d < || |d < t ||d D ]}||| |< q:|| |d  d || |d < | | ||d  |< dad S )Nr'   r      r%      )r*   rC   )Z	Array1ParZ	Array2ParrL   rM   rD   ZIntIndexr   r   r   r6      s     r6   c                 C   s   | }|}||krt S tS d S r   )r-   r2   )ZCharPar1ZCharPar2ZCharLoc1ZCharLoc2r   r   r   r:      s
    r:   c                 C   sp   d}|dkr4t | | ||d  tkrd}|d }q|dkrH|dkrHd}|dkrTtS | |krh|d }tS tS d S )Nr   r(   WZr$   X)r:   r-   TRUErG   )ZStrParI1ZStrParI2rD   ZCharLocr   r   r   r3      s    
r3   c                 C   s   | }|t krtS tS r   )r.   rS   rG   )rK   r@   r   r   r   rH      s     rH   __main__c                 C   s6   t | dtjd t dtjd  tjd td d S )N )endfilezusage: %s [number_of_loops]r   )rW   rE   )r   sysstderrargvexit)msgr   r   r   error  s    r]   z%d arguments are too many;zInvalid argument %r;)0__doc__Z
__future__r   timer   ZLOOPSr   r*   r-   r2   r.   rI   rJ   objectr   rS   rG   r   r   rC   r4   rB   r9   r7   r/   r,   r+   r   r8   r>   rA   r1   r0   r;   r5   r6   r:   r3   rH   r   rX   r]   lenrZ   nargsintr   
ValueErrorr   r   r   r   <module>   sV    
:



 