daily pastebin goal
38%
SHARE
TWEET

pystone 1.1

a guest Jul 11th, 2014 121 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. LOOPS = 50000
  2.  
  3. from time import clock
  4.  
  5. __version__ = "1.1"
  6.  
  7. [Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6)
  8.  
  9. class Record:
  10.  
  11.     def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0,
  12.                        IntComp = 0, StringComp = 0):
  13.         self.PtrComp = PtrComp
  14.         self.Discr = Discr
  15.         self.EnumComp = EnumComp
  16.         self.IntComp = IntComp
  17.         self.StringComp = StringComp
  18.  
  19.     def copy(self):
  20.         return Record(self.PtrComp, self.Discr, self.EnumComp,
  21.                       self.IntComp, self.StringComp)
  22.  
  23. TRUE = 1
  24. FALSE = 0
  25.  
  26. def main(loops=LOOPS):
  27.     benchtime, stones = pystones(loops)
  28.     print "Pystone(%s) time for %d passes = %g" % \
  29.           (__version__, loops, benchtime)
  30.     print "This machine benchmarks at %g pystones/second" % stones
  31.  
  32.  
  33. def pystones(loops=LOOPS):
  34.     return Proc0(loops)
  35.  
  36. IntGlob = 0
  37. BoolGlob = FALSE
  38. Char1Glob = '\0'
  39. Char2Glob = '\0'
  40. Array1Glob = [0]*51
  41. Array2Glob = map(lambda x: x[:], [Array1Glob]*51)
  42. PtrGlb = None
  43. PtrGlbNext = None
  44.  
  45. def Proc0(loops=LOOPS):
  46.     global IntGlob
  47.     global BoolGlob
  48.     global Char1Glob
  49.     global Char2Glob
  50.     global Array1Glob
  51.     global Array2Glob
  52.     global PtrGlb
  53.     global PtrGlbNext
  54.  
  55.     starttime = clock()
  56.     for i in range(loops):
  57.         pass
  58.     nulltime = clock() - starttime
  59.  
  60.     PtrGlbNext = Record()
  61.     PtrGlb = Record()
  62.     PtrGlb.PtrComp = PtrGlbNext
  63.     PtrGlb.Discr = Ident1
  64.     PtrGlb.EnumComp = Ident3
  65.     PtrGlb.IntComp = 40
  66.     PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING"
  67.     String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING"
  68.     Array2Glob[8][7] = 10
  69.  
  70.     starttime = clock()
  71.  
  72.     for i in range(loops):
  73.         Proc5()
  74.         Proc4()
  75.         IntLoc1 = 2
  76.         IntLoc2 = 3
  77.         String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING"
  78.         EnumLoc = Ident2
  79.         BoolGlob = not Func2(String1Loc, String2Loc)
  80.         while IntLoc1 < IntLoc2:
  81.             IntLoc3 = 5 * IntLoc1 - IntLoc2
  82.             IntLoc3 = Proc7(IntLoc1, IntLoc2)
  83.             IntLoc1 = IntLoc1 + 1
  84.         Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
  85.         PtrGlb = Proc1(PtrGlb)
  86.         CharIndex = 'A'
  87.         while CharIndex <= Char2Glob:
  88.             if EnumLoc == Func1(CharIndex, 'C'):
  89.                 EnumLoc = Proc6(Ident1)
  90.             CharIndex = chr(ord(CharIndex)+1)
  91.         IntLoc3 = IntLoc2 * IntLoc1
  92.         IntLoc2 = IntLoc3 / IntLoc1
  93.         IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
  94.         IntLoc1 = Proc2(IntLoc1)
  95.  
  96.     benchtime = clock() - starttime - nulltime
  97.     if benchtime == 0.0:
  98.         loopsPerBenchtime = 0.0
  99.     else:
  100.         loopsPerBenchtime = (loops / benchtime)
  101.     return benchtime, loopsPerBenchtime
  102.  
  103. def Proc1(PtrParIn):
  104.     PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
  105.     PtrParIn.IntComp = 5
  106.     NextRecord.IntComp = PtrParIn.IntComp
  107.     NextRecord.PtrComp = PtrParIn.PtrComp
  108.     NextRecord.PtrComp = Proc3(NextRecord.PtrComp)
  109.     if NextRecord.Discr == Ident1:
  110.         NextRecord.IntComp = 6
  111.         NextRecord.EnumComp = Proc6(PtrParIn.EnumComp)
  112.         NextRecord.PtrComp = PtrGlb.PtrComp
  113.         NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
  114.     else:
  115.         PtrParIn = NextRecord.copy()
  116.     NextRecord.PtrComp = None
  117.     return PtrParIn
  118.  
  119. def Proc2(IntParIO):
  120.     IntLoc = IntParIO + 10
  121.     while 1:
  122.         if Char1Glob == 'A':
  123.             IntLoc = IntLoc - 1
  124.             IntParIO = IntLoc - IntGlob
  125.             EnumLoc = Ident1
  126.         if EnumLoc == Ident1:
  127.             break
  128.     return IntParIO
  129.  
  130. def Proc3(PtrParOut):
  131.     global IntGlob
  132.  
  133.     if PtrGlb is not None:
  134.         PtrParOut = PtrGlb.PtrComp
  135.     else:
  136.         IntGlob = 100
  137.     PtrGlb.IntComp = Proc7(10, IntGlob)
  138.     return PtrParOut
  139.  
  140. def Proc4():
  141.     global Char2Glob
  142.  
  143.     BoolLoc = Char1Glob == 'A'
  144.     BoolLoc = BoolLoc or BoolGlob
  145.     Char2Glob = 'B'
  146.  
  147. def Proc5():
  148.     global Char1Glob
  149.     global BoolGlob
  150.  
  151.     Char1Glob = 'A'
  152.     BoolGlob = FALSE
  153.  
  154. def Proc6(EnumParIn):
  155.     EnumParOut = EnumParIn
  156.     if not Func3(EnumParIn):
  157.         EnumParOut = Ident4
  158.     if EnumParIn == Ident1:
  159.         EnumParOut = Ident1
  160.     elif EnumParIn == Ident2:
  161.         if IntGlob > 100:
  162.             EnumParOut = Ident1
  163.         else:
  164.             EnumParOut = Ident4
  165.     elif EnumParIn == Ident3:
  166.         EnumParOut = Ident2
  167.     elif EnumParIn == Ident4:
  168.         pass
  169.     elif EnumParIn == Ident5:
  170.         EnumParOut = Ident3
  171.     return EnumParOut
  172.  
  173. def Proc7(IntParI1, IntParI2):
  174.     IntLoc = IntParI1 + 2
  175.     IntParOut = IntParI2 + IntLoc
  176.     return IntParOut
  177.  
  178. def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
  179.     global IntGlob
  180.  
  181.     IntLoc = IntParI1 + 5
  182.     Array1Par[IntLoc] = IntParI2
  183.     Array1Par[IntLoc+1] = Array1Par[IntLoc]
  184.     Array1Par[IntLoc+30] = IntLoc
  185.     for IntIndex in range(IntLoc, IntLoc+2):
  186.         Array2Par[IntLoc][IntIndex] = IntLoc
  187.     Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1
  188.     Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
  189.     IntGlob = 5
  190.  
  191. def Func1(CharPar1, CharPar2):
  192.     CharLoc1 = CharPar1
  193.     CharLoc2 = CharLoc1
  194.     if CharLoc2 != CharPar2:
  195.         return Ident1
  196.     else:
  197.         return Ident2
  198.  
  199. def Func2(StrParI1, StrParI2):
  200.     IntLoc = 1
  201.     while IntLoc <= 1:
  202.         if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
  203.             CharLoc = 'A'
  204.             IntLoc = IntLoc + 1
  205.     if CharLoc >= 'W' and CharLoc <= 'Z':
  206.         IntLoc = 7
  207.     if CharLoc == 'X':
  208.         return TRUE
  209.     else:
  210.         if StrParI1 > StrParI2:
  211.             IntLoc = IntLoc + 7
  212.             return TRUE
  213.         else:
  214.             return FALSE
  215.  
  216. def Func3(EnumParIn):
  217.     EnumLoc = EnumParIn
  218.     if EnumLoc == Ident3: return TRUE
  219.     return FALSE
  220.  
  221. if __name__ == '__main__':
  222.     import sys
  223.     def error(msg):
  224.         print >>sys.stderr, msg,
  225.         print >>sys.stderr, "usage: %s [number_of_loops]" % sys.argv[0]
  226.         sys.exit(100)
  227.     nargs = len(sys.argv) - 1
  228.     if nargs > 1:
  229.         error("%d arguments are too many;" % nargs)
  230.     elif nargs == 1:
  231.         try: loops = int(sys.argv[1])
  232.         except ValueError:
  233.             error("Invalid argument %r;" % sys.argv[1])
  234.     else:
  235.         loops = LOOPS
  236.     main(loops)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top