ó
è¾bc           @   sç  d  Z  d Z d d l m Z d Z e d d ƒ \ Z Z Z Z	 Z
 d d  d „  ƒ  YZ d Z d	 Z e d
 „ Z e d „ Z d	 a e a d a d a d	 g d a e d „  t g d ƒ a d a d a e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d „  Z# d „  Z$ d „  Z% e& d k rãd d l' Z' d „  Z( e) e' j* ƒ d Z+ e+ d k re( d e+ ƒ nU e+ d k rÐy e, e' j* d ƒ Z- WqÖe. k
 rÌe( d e' j* d ƒ qÖXn e Z- e e- ƒ n  d S(!   sâ  
"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.

iPÃ  iÿÿÿÿ(   t   clocks   1.1i   i   t   Recordc           B   s)   e  Z d d  d  d  d  d „ Z d „  Z RS(   i    c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   t   PtrCompt   Discrt   EnumCompt   IntCompt
   StringComp(   t   selfR   R   R   R   R   (    (    s"   /usr/lib/python2.7/test/pystone.pyt   __init__-   s
    				c         C   s%   t  |  j |  j |  j |  j |  j ƒ S(   N(   R   R   R   R   R   R   (   R   (    (    s"   /usr/lib/python2.7/test/pystone.pyt   copy5   s    N(   t   __name__t
   __module__t   NoneR   R	   (    (    (    s"   /usr/lib/python2.7/test/pystone.pyR   +   s   	i    c         C   s1   t  |  ƒ \ } } d t |  | f GHd | GHd  S(   Ns#   Pystone(%s) time for %d passes = %gs-   This machine benchmarks at %g pystones/second(   t   pystonest   __version__(   t   loopst	   benchtimet   stones(    (    s"   /usr/lib/python2.7/test/pystone.pyt   main<   s    c         C   s
   t  |  ƒ S(   N(   t   Proc0(   R   (    (    s"   /usr/lib/python2.7/test/pystone.pyR   C   s    s    i3   c         C   s   |  S(   N(    (   t   x(    (    s"   /usr/lib/python2.7/test/pystone.pyt   <lambda>K   t    c         C   sî  t  ƒ  } x t |  ƒ D] } q Wt  ƒ  | } t ƒ  a t ƒ  a t t _ t t _ t t _	 d t _
 d t _ d } d t d d <t  ƒ  } x(t |  ƒ D]} t ƒ  t ƒ  d } d } d	 } t } t | | ƒ a x7 | | k  rd
 | | }	 t | | ƒ }	 | d } qÕ Wt t t | |	 ƒ t t ƒ a d }
 xJ |
 t k r}| t |
 d ƒ k rdt t ƒ } n  t t |
 ƒ d ƒ }
 q4W| | }	 |	 | } d |	 | | } t | ƒ } q– Wt  ƒ  | | } | d k rÚd } n
 |  | } | | f S(   Ni(   s   DHRYSTONE PROGRAM, SOME STRINGs   DHRYSTONE PROGRAM, 1'ST STRINGi
   i   i   i   i   s   DHRYSTONE PROGRAM, 2'ND STRINGi   i   t   At   Cg        (   R    t   rangeR   t
   PtrGlbNextt   PtrGlbR   t   Ident1R   t   Ident3R   R   R   t
   Array2Globt   Proc5t   Proc4t   Ident2t   Func2t   BoolGlobt   Proc7t   Proc8t
   Array1Globt   Proc1t	   Char2Globt   Func1t   Proc6t   chrt   ordt   Proc2(   R   t	   starttimet   it   nulltimet
   String1Loct   IntLoc1t   IntLoc2t
   String2Loct   EnumLoct   IntLoc3t	   CharIndexR   t   loopsPerBenchtime(    (    s"   /usr/lib/python2.7/test/pystone.pyR   O   sT    
									

	
c         C   s­   t  j ƒ  |  _ } d |  _ |  j | _ |  j | _ t | j ƒ | _ | j t k r” d | _ t |  j ƒ | _ t  j | _ t	 | j d ƒ | _ n | j ƒ  }  d  | _ |  S(   Ni   i   i
   (   R   R	   R   R   t   Proc3R   R   R*   R   R$   R   (   t   PtrParInt
   NextRecord(    (    s"   /usr/lib/python2.7/test/pystone.pyR'   ‰   s    			c         C   sN   |  d } x= t  d k r6 | d } | t }  t } n  | t k r Pq q W|  S(   Ni
   R   i   (   t	   Char1Globt   IntGlobR   (   t   IntParIOt   IntLocR5   (    (    s"   /usr/lib/python2.7/test/pystone.pyR-   ™   s    


	c         C   s4   t  d  k	 r t  j }  n d a t d t ƒ t  _ |  S(   Nid   i
   (   R   R   R   R=   R$   R   (   t	   PtrParOut(    (    s"   /usr/lib/python2.7/test/pystone.pyR9   ¤   s
    c          C   s"   t  d k }  |  p t }  d a d  S(   NR   t   B(   R<   R#   R(   (   t   BoolLoc(    (    s"   /usr/lib/python2.7/test/pystone.pyR    ®   s    c           C   s   d a  t a d  S(   NR   (   R<   t   FALSER#   (    (    (    s"   /usr/lib/python2.7/test/pystone.pyR   µ   s    c         C   s—   |  } t  |  ƒ s t } n  |  t k r0 t } nc |  t k rZ t d k rQ t } q“ t } n9 |  t k ro t } n$ |  t k r~ n |  t k r“ t } n  | S(   Nid   (   t   Func3t   Ident4R   R!   R=   R   t   Ident5(   t	   EnumParInt
   EnumParOut(    (    s"   /usr/lib/python2.7/test/pystone.pyR*   ¼   s     						c         C   s   |  d } | | } | S(   Ni   (    (   t   IntParI1t   IntParI2R?   t	   IntParOut(    (    s"   /usr/lib/python2.7/test/pystone.pyR$   Ï   s    

c         C   s¢   | d } | |  | <|  | |  | d <| |  | d <x) t  | | d ƒ D] } | | | | <qH W| | | d d | | | d <|  | | | d | <d a d  S(   Ni   i   i   i   i   (   R   R=   (   t	   Array1Part	   Array2ParRI   RJ   R?   t   IntIndex(    (    s"   /usr/lib/python2.7/test/pystone.pyR%   Ô   s    

"c         C   s$   |  } | } | | k r t  St Sd  S(   N(   R   R!   (   t   CharPar1t   CharPar2t   CharLoc1t   CharLoc2(    (    s"   /usr/lib/python2.7/test/pystone.pyR)   á   s
    c         C   s    d } xD | d k rL t  |  | | | d ƒ t k r	 d } | d } q	 q	 W| d k rn | d k rn d } n  | d k r~ t S|  | k r˜ | d } t St Sd  S(   Ni   R   t   Wt   Zi   t   X(   R)   R   t   TRUERC   (   t   StrParI1t   StrParI2R?   t   CharLoc(    (    s"   /usr/lib/python2.7/test/pystone.pyR"   é   s    !	
c         C   s   |  } | t  k r t St S(   N(   R   RV   RC   (   RG   R5   (    (    s"   /usr/lib/python2.7/test/pystone.pyRD   ú   s     t   __main__Nc         C   s6   t  j |  It  j d t  j d IJt  j d ƒ d  S(   Ns   usage: %s [number_of_loops]i    id   (   t   syst   stderrt   argvt   exit(   t   msg(    (    s"   /usr/lib/python2.7/test/pystone.pyt   error  s    s   %d arguments are too many;s   Invalid argument %r;(    (/   t   __doc__t   LOOPSt   timeR    R   R   R   R!   R   RE   RF   R   RV   RC   R   R   R=   R#   R<   R(   R&   t   mapR   R   R   R   R   R'   R-   R9   R    R   R*   R$   R%   R)   R"   RD   R
   R[   R`   t   lenR]   t   nargst   intR   t
   ValueError(    (    (    s"   /usr/lib/python2.7/test/pystone.pyt   <module>!   sT   :			
									 