o ,]@sdZddlmZddlmZdZdZedd\ZZ Z Z Z Gdd d e ZdZdZefd d Zefd d ZdaeadadadgdaddtgdDadadaefddZddZddZddZddZddZ dd Z!d!d"Z"d#d$Z#d%d&Z$d'd(Z%d)d*Z&e'd+krddl(Z(d,d-Z)e*e(j+dZ,e,dkre)d.e,n"e,dkrz e-e(j+dZ.Wne/ye)d/e(j+dYnweZ.ee.dSdS)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)clockiPz1.1c@s"eZdZ  dddZddZdS)RecordNrcCs"||_||_||_||_||_dSN)PtrCompDiscrEnumCompIntComp StringComp)selfrr r r r r?/usr/lib/python3/dist-packages/future/backports/test/pystone.py__init__/s  zRecord.__init__cCst|j|j|j|j|jSr)rrr r r r )r rrrcopy7sz Record.copy)Nrrrr)__name__ __module__ __qualname__rrrrrrr-s  rcCs.t|\}}tdt||ftd|dS)Nz#Pystone(%s) time for %d passes = %gz-This machine benchmarks at %g pystones/second)pystonesprint __version__)loops benchtimestonesrrrmain>s rcCst|Sr)Proc0)rrrrrEsr3cCsg|]}|ddqSrr).0xrrr Msr!Nc Cslt}t|D]}qt|}tatatt_tt_tt_ dt_ dt_ d}dt dd<t}t|D]i}t td}d}d }t}t|| a||kr`d ||} t||} |d }||ksMttt || ttad } | tkr|t| d kr|tt}tt| d } | tksq||} | |}d| ||}t|}q3t||} | dkrd} | | fS|| } | | fS)N(zDHRYSTONE PROGRAM, SOME STRINGzDHRYSTONE PROGRAM, 1'ST STRING zDHRYSTONE PROGRAM, 2'ND STRINGrACg)rranger PtrGlbNextPtrGlbrIdent1r Ident3r r r Array2GlobProc5Proc4Ident2Func2BoolGlobProc7Proc8 Array1GlobProc1 Char2GlobFunc1Proc6chrordProc2) r starttimeinulltime String1LocIntLoc1IntLoc2 String2LocEnumLocIntLoc3 CharIndexrloopsPerBenchtimerrrrQsZ        rcCsvt|_}d|_|j|_|j|_t|j|_|jtkr2d|_t|j|_tj|_t |jd|_n|}d|_|S)Nr(rr#) r-rrr Proc3r r.r<r r6)PtrParIn NextRecordrrrr9s   r9cCs6|d} tdkr|d}|t}t}|tkr |Sq)Nr#rr)) Char1GlobIntGlobr.)IntParIOIntLocrGrrrr?sr?cCs$tdurtj}ndatdtt_|S)Ndr#)r-rrOr6r ) PtrParOutrrrrKs  rKcCstdk}|pt}dadS)Nr)B)rNr5r:)BoolLocrrrr2sr2cCs datadS)Nr))rNFALSEr5rrrrr1sr1cCsn|}t|st}|tkrt}|S|tkr tdkrt}|St}|S|tkr(t}|S|tkr/ |S|tkr5t}|S)NrR)Func3Ident4r.r3rOr/Ident5) EnumParIn EnumParOutrrrr<s*  r<cCs|d}||}|S)Nr&r)IntParI1IntParI2rQ IntParOutrrrr6sr6cCs|d}|||<||||d<|||d<t||dD]}||||<q|||dd|||d<||||d|<dadS)Nr(rr&)r+rO) Array1Par Array2Parr\r]rQIntIndexrrrr7s  r7cCs|}|}||kr tStSr)r.r3)CharPar1CharPar2CharLoc1CharLoc2rrrr;s r;cCsrd}|dkrt||||dtkrd}|d}|dks|dkr'|dkr'd}|dkr-tS||kr7|d}tStS)Nrr)WZr%X)r;r.TRUErV)StrParI1StrParI2rQCharLocrrrr4sr4cCs|}|tkrtStSr)r/rkrV)rZrGrrrrWs rW__main__cCs6t|dtjdtdtjdtjdtddS)N )endfilezusage: %s [number_of_loops]r)rrrR)rsysstderrargvexit)msgrrrerrorsrxz%d arguments are too many;zInvalid argument %r;)0__doc__ __future__rtimerLOOPSrr+r.r3r/rXrYobjectrrkrVrrrOr5rNr:r8r0r-r,rr9r?rKr2r1r<r6r7r;r4rWrrsrxlenrunargsintr ValueErrorrrrrsZ     :