o
    0ÿ¿c  ã                   @   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rÇddl(Z(d,d-„ Z)e*e(j+ƒd Z,e,dkrŸe)d.e, ƒ n"e,dkr¿z	e-e(j+d ƒZ.W n e/y¾   e)d/e(j+d  ƒ Y nw eZ.ee.ƒ dS 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   úMD:\Projects\ConvertPro\env\Lib\site-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   sl  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 ]i}tƒ  tƒ  d}d}d	}t}t||ƒ a||k r`d
| | }	t||ƒ}	|d }||k sMttt||	ƒ ttƒad}
|
tkrˆ|t|
dƒkr|ttƒ}tt|
ƒd ƒ}
|
tksq|| }	|	| }d|	|  | }t|ƒ}q3t ƒ | | }|dkr®d}||fS | | }||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   sZ   


ýý
ÿr   c                 C   sv   t  ¡  | _}d| _| j|_| j|_t|jƒ|_|jtkr2d|_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   s6   | d }	 t dkr|d }|t } t}|tkr	 | S q)Nr"   r   r(   )Ú	Char1GlobÚIntGlobr-   )ZIntParIOÚIntLocr@   r   r   r   r>   ›   s   ùr>   c                 C   s$   t d urt j} ndatdtƒt _| S )Néd   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   sn   | }t | ƒst}| tkrt}|S | tkr tdkrt}|S t}|S | tkr(t}|S | tkr/	 |S | tkr5t}|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 r   )r-   r2   )ZCharPar1ZCharPar2ZCharLoc1ZCharLoc2r   r   r   r:   ã   s
   r:   c                 C   sr   d}|dkrt | | ||d  ƒtkrd}|d }|dks|dkr'|dkr'd}|dkr-tS | |kr7|d }tS t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__Ú
__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>   sZ    
:
ÿñ