3
^d1                 @   s  d Z dZddlmZ dZedd\ZZZZZ	G dd d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r4e%d-e(  nLe(dkr|ye)e$j'd Z*W n( e+k
rx   e%d.e$j'd   Y nX neZ*ee* dS )/aD  
"PYSTONE" Benchmark Program

Version:        Python/1.2 (corresponds to C/1.1 plus 3 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.

                Version 1.2 changes the division to floor division.

                Under Python 3 version 1.1 would use the normal division
                operator, resulting in some of the operations mistakenly
                yielding floats. Version 1.2 instead uses floor division
                making the benchmark an integer benchmark again.

iP      )timez1.2      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.6/test/pystone.py__init__4   s
    zRecord.__init__c             C   s   t | j| j| j| j| jS )N)r   r   r   r   r	   r
   )r   r   r   r   copy<   s    zRecord.copy)Nr   r   r   r   )__name__
__module____qualname__r   r   r   r   r   r   r   2   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   mainC   s    r   c             C   s   t | S )N)Proc0)r   r   r   r   r   J   s    r    3   c             C   s   g | ]}|d d  qS )Nr   ).0xr   r   r   
<listcomp>R   s    r   Nc             C   sp  t  }xt| D ]}qW t  | }t at att_tt_tt_	dt_
dt_d}dtd d< t  }xt| D ]}t  t  d}d}d	}t}t|| ax*||k rd
| | }	t||}	|d }qW ttt||	 ttad}
x6|
tkr|t|
dkrtt}tt|
d }
qW || }	|	| }d|	|  | }t|}qlW t  | | }|dkr`d}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   V   sT    




r   c             C   sv   t j  | _}d| _| j|_| j|_t|j|_|jtkrdd|_t| j|_t j|_t	|jd|_n|j } d |_| S )Nr%   r   r    )
r*   r   r   r	   Proc3r   r+   r9   r   r3   )ZPtrParInZ
NextRecordr   r   r   r6      s    
r6   c             C   s8   | d }x*t dkr&|d }|t } t}|tkr
P q
W | 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   rA   r3   r	   )Z	PtrParOutr   r   r   r?      s
    r?   c              C   s   t dk} | pt} dad S )Nr&   B)r@   r2   r7   )ZBoolLocr   r   r   r/      s    r/   c               C   s   da tad S )Nr&   )r@   FALSEr2   r   r   r   r   r.      s    r.   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 )NrC   )Func3Ident4r+   r0   rA   r,   Ident5)	EnumParInZ
EnumParOutr   r   r   r9      s     r9   c             C   s   | d }|| }|S )Nr#   r   )IntParI1IntParI2rB   Z	IntParOutr   r   r   r3      s    r3   c             C   s   |d }|| |< | | | |d < || |d < x"t ||d D ]}||| |< q<W || |d  d || |d < | | ||d  |< dad S )Nr%   r      r#      )r(   rA   )Z	Array1ParZ	Array2ParrJ   rK   rB   ZIntIndexr   r   r   r4      s     r4   c             C   s   | }|}||krt S tS d S )N)r+   r0   )ZCharPar1ZCharPar2ZCharLoc1ZCharLoc2r   r   r   r8      s
    r8   c             C   st   d}x2|dkr6t | | ||d  tkrd}|d }qW |dkrL|dkrLd}|dkrXtS | |krl|d }tS tS d S )Nr   r&   WZr"   X)r8   r+   TRUErE   )ZStrParI1ZStrParI2rB   ZCharLocr   r   r   r1      s    
r1   c             C   s   | }|t krtS tS )N)r,   rQ   rE   )rI   r>   r   r   r   rF     s     rF   __main__c             C   s6   t | dtjd t dtjd  tjd tjd d S )N )endfilezusage: %s [number_of_loops]r   )rU   rC   )r   sysstderrargvexit)msgr   r   r   error  s    r[   z%d arguments are too many;zInvalid argument %r;),__doc__ZLOOPSr   r   r(   r+   r0   r,   rG   rH   r   rQ   rE   r   r   rA   r2   r@   r7   r5   r-   r*   r)   r   r6   r<   r?   r/   r.   r9   r3   r4   r8   r1   rF   r   rV   r[   lenrX   nargsintr   
ValueErrorr   r   r   r   <module>(   sT   
:



 