| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 6f9e433 commit 189f8fb
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,229 @@ | |||
| 1 | + #! /usr/local/bin/python | ||
| 2 | + | ||
| 3 | + """ | ||
| 4 | + "PYSTONE" Benchmark Program | ||
| 5 | + | ||
| 6 | + Version: Python/1.0 (corresponds to C/1.1) | ||
| 7 | + | ||
| 8 | + Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013. | ||
| 9 | + | ||
| 10 | + Translated from ADA to C by Rick Richardson. | ||
| 11 | + Every method to preserve ADA-likeness has been used, | ||
| 12 | + at the expense of C-ness. | ||
| 13 | + | ||
| 14 | + Translated from C to Python by Guido van Rossum. | ||
| 15 | + """ | ||
| 16 | + | ||
| 17 | + LOOPS = 1000 | ||
| 18 | + | ||
| 19 | + from time import clock | ||
| 20 | + | ||
| 21 | + __version__ = "1.0" | ||
| 22 | + | ||
| 23 | + [Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6) | ||
| 24 | + | ||
| 25 | + class Record: | ||
| 26 | + | ||
| 27 | + def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0, | ||
| 28 | + IntComp = 0, StringComp = 0): | ||
| 29 | + self.PtrComp = PtrComp | ||
| 30 | + self.Discr = Discr | ||
| 31 | + self.EnumComp = EnumComp | ||
| 32 | + self.IntComp = IntComp | ||
| 33 | + self.StringComp = StringComp | ||
| 34 | + | ||
| 35 | + def copy(self): | ||
| 36 | + return Record(self.PtrComp, self.Discr, self.EnumComp, | ||
| 37 | + self.IntComp, self.StringComp) | ||
| 38 | + | ||
| 39 | + TRUE = 1 | ||
| 40 | + FALSE = 0 | ||
| 41 | + | ||
| 42 | + def main(): | ||
| 43 | + Proc0() | ||
| 44 | + | ||
| 45 | + IntGlob = 0 | ||
| 46 | + BoolGlob = FALSE | ||
| 47 | + Char1Glob = '\0' | ||
| 48 | + Char2Glob = '\0' | ||
| 49 | + Array1Glob = [0]*51 | ||
| 50 | + Array2Glob = map(lambda x: x[:], [Array1Glob]*51) | ||
| 51 | + PtrGlb = None | ||
| 52 | + PtrGlbNext = None | ||
| 53 | + | ||
| 54 | + def Proc0(): | ||
| 55 | + global IntGlob | ||
| 56 | + global BoolGlob | ||
| 57 | + global Char1Glob | ||
| 58 | + global Char2Glob | ||
| 59 | + global Array1Glob | ||
| 60 | + global Array2Glob | ||
| 61 | + global PtrGlb | ||
| 62 | + global PtrGlbNext | ||
| 63 | + | ||
| 64 | + starttime = clock() | ||
| 65 | + for i in range(LOOPS): | ||
| 66 | + pass | ||
| 67 | + nulltime = clock() - starttime | ||
| 68 | + | ||
| 69 | + PtrGlbNext = Record() | ||
| 70 | + PtrGlb = Record() | ||
| 71 | + PtrGlb.PtrComp = PtrGlbNext | ||
| 72 | + PtrGlb.Discr = Ident1 | ||
| 73 | + PtrGlb.EnumComp = Ident3 | ||
| 74 | + PtrGlb.IntComp = 40 | ||
| 75 | + PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING" | ||
| 76 | + String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING" | ||
| 77 | + Array2Glob[8][7] = 10 | ||
| 78 | + | ||
| 79 | + starttime = clock() | ||
| 80 | + | ||
| 81 | + for i in range(LOOPS): | ||
| 82 | + Proc5() | ||
| 83 | + Proc4() | ||
| 84 | + IntLoc1 = 2 | ||
| 85 | + IntLoc2 = 3 | ||
| 86 | + String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING" | ||
| 87 | + EnumLoc = Ident2 | ||
| 88 | + BoolGlob = not Func2(String1Loc, String2Loc) | ||
| 89 | + while IntLoc1 < IntLoc2: | ||
| 90 | + IntLoc3 = 5 * IntLoc1 - IntLoc2 | ||
| 91 | + IntLoc3 = Proc7(IntLoc1, IntLoc2) | ||
| 92 | + IntLoc1 = IntLoc1 + 1 | ||
| 93 | + Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3) | ||
| 94 | + PtrGlb = Proc1(PtrGlb) | ||
| 95 | + CharIndex = 'A' | ||
| 96 | + while CharIndex <= Char2Glob: | ||
| 97 | + if EnumLoc == Func1(CharIndex, 'C'): | ||
| 98 | + EnumLoc = Proc6(Ident1) | ||
| 99 | + CharIndex = chr(ord(CharIndex)+1) | ||
| 100 | + IntLoc3 = IntLoc2 * IntLoc1 | ||
| 101 | + IntLoc2 = IntLoc3 / IntLoc1 | ||
| 102 | + IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1 | ||
| 103 | + IntLoc1 = Proc2(IntLoc1) | ||
| 104 | + | ||
| 105 | + benchtime = clock() - starttime - nulltime | ||
| 106 | + print "Pystone(%s) time for %d passes = %g" % \ | ||
| 107 | + (__version__, LOOPS, benchtime) | ||
| 108 | + print "This machine benchmarks at %g pystones/second" % \ | ||
| 109 | + (LOOPS/benchtime) | ||
| 110 | + | ||
| 111 | + def Proc1(PtrParIn): | ||
| 112 | + PtrParIn.PtrComp = NextRecord = PtrGlb.copy() | ||
| 113 | + PtrParIn.IntComp = 5 | ||
| 114 | + NextRecord.IntComp = PtrParIn.IntComp | ||
| 115 | + NextRecord.PtrComp = PtrParIn.PtrComp | ||
| 116 | + NextRecord.PtrComp = Proc3(NextRecord.PtrComp) | ||
| 117 | + if NextRecord.Discr == Ident1: | ||
| 118 | + NextRecord.IntComp = 6 | ||
| 119 | + NextRecord.EnumComp = Proc6(PtrParIn.EnumComp) | ||
| 120 | + NextRecord.PtrComp = PtrGlb.PtrComp | ||
| 121 | + NextRecord.IntComp = Proc7(NextRecord.IntComp, 10) | ||
| 122 | + else: | ||
| 123 | + PtrParIn = NextRecord.copy() | ||
| 124 | + return PtrParIn | ||
| 125 | + | ||
| 126 | + def Proc2(IntParIO): | ||
| 127 | + IntLoc = IntParIO + 10 | ||
| 128 | + while 1: | ||
| 129 | + if Char1Glob == 'A': | ||
| 130 | + IntLoc = IntLoc - 1 | ||
| 131 | + IntParIO = IntLoc - IntGlob | ||
| 132 | + EnumLoc = Ident1 | ||
| 133 | + if EnumLoc == Ident1: | ||
| 134 | + break | ||
| 135 | + return IntParIO | ||
| 136 | + | ||
| 137 | + def Proc3(PtrParOut): | ||
| 138 | + global IntGlob | ||
| 139 | + | ||
| 140 | + if PtrGlb != None: | ||
| 141 | + PtrParOut = PtrGlb.PtrComp | ||
| 142 | + else: | ||
| 143 | + IntGlob = 100 | ||
| 144 | + PtrGlb.IntComp = Proc7(10, IntGlob) | ||
| 145 | + return PtrParOut | ||
| 146 | + | ||
| 147 | + def Proc4(): | ||
| 148 | + global Char2Glob | ||
| 149 | + | ||
| 150 | + BoolLoc = Char1Glob == 'A' | ||
| 151 | + BoolLoc = BoolLoc or BoolGlob | ||
| 152 | + Char2Glob = 'B' | ||
| 153 | + | ||
| 154 | + def Proc5(): | ||
| 155 | + global Char1Glob | ||
| 156 | + global BoolGlob | ||
| 157 | + | ||
| 158 | + Char1Glob = 'A' | ||
| 159 | + BoolGlob = FALSE | ||
| 160 | + | ||
| 161 | + def Proc6(EnumParIn): | ||
| 162 | + EnumParOut = EnumParIn | ||
| 163 | + if not Func3(EnumParIn): | ||
| 164 | + EnumParOut = Ident4 | ||
| 165 | + if EnumParIn == Ident1: | ||
| 166 | + EnumParOut = Ident1 | ||
| 167 | + elif EnumParIn == Ident2: | ||
| 168 | + if IntGlob > 100: | ||
| 169 | + EnumParOut = Ident1 | ||
| 170 | + else: | ||
| 171 | + EnumParOut = Ident4 | ||
| 172 | + elif EnumParIn == Ident3: | ||
| 173 | + EnumParOut = Ident2 | ||
| 174 | + elif EnumParIn == Ident4: | ||
| 175 | + pass | ||
| 176 | + elif EnumParIn == Ident5: | ||
| 177 | + EnumParOut = Ident3 | ||
| 178 | + return EnumParOut | ||
| 179 | + | ||
| 180 | + def Proc7(IntParI1, IntParI2): | ||
| 181 | + IntLoc = IntParI1 + 2 | ||
| 182 | + IntParOut = IntParI2 + IntLoc | ||
| 183 | + return IntParOut | ||
| 184 | + | ||
| 185 | + def Proc8(Array1Par, Array2Par, IntParI1, IntParI2): | ||
| 186 | + global IntGlob | ||
| 187 | + | ||
| 188 | + IntLoc = IntParI1 + 5 | ||
| 189 | + Array1Par[IntLoc] = IntParI2 | ||
| 190 | + Array1Par[IntLoc+1] = Array1Par[IntLoc] | ||
| 191 | + Array1Par[IntLoc+30] = IntLoc | ||
| 192 | + for IntIndex in range(IntLoc, IntLoc+2): | ||
| 193 | + Array2Par[IntLoc][IntIndex] = IntLoc | ||
| 194 | + Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1 | ||
| 195 | + Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc] | ||
| 196 | + IntGlob = 5 | ||
| 197 | + | ||
| 198 | + def Func1(CharPar1, CharPar2): | ||
| 199 | + CharLoc1 = CharPar1 | ||
| 200 | + CharLoc2 = CharLoc1 | ||
| 201 | + if CharLoc2 != CharPar2: | ||
| 202 | + return Ident1 | ||
| 203 | + else: | ||
| 204 | + return Ident2 | ||
| 205 | + | ||
| 206 | + def Func2(StrParI1, StrParI2): | ||
| 207 | + IntLoc = 1 | ||
| 208 | + while IntLoc <= 1: | ||
| 209 | + if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1: | ||
| 210 | + CharLoc = 'A' | ||
| 211 | + IntLoc = IntLoc + 1 | ||
| 212 | + if CharLoc >= 'W' and CharLoc <= 'Z': | ||
| 213 | + IntLoc = 7 | ||
| 214 | + if CharLoc == 'X': | ||
| 215 | + return TRUE | ||
| 216 | + else: | ||
| 217 | + if StrParI1 > StrParI2: | ||
| 218 | + IntLoc = IntLoc + 7 | ||
| 219 | + return TRUE | ||
| 220 | + else: | ||
| 221 | + return FALSE | ||
| 222 | + | ||
| 223 | + def Func3(EnumParIn): | ||
| 224 | + EnumLoc = EnumParIn | ||
| 225 | + if EnumLoc == Ident3: return TRUE | ||
| 226 | + return FALSE | ||
| 227 | + | ||
| 228 | + if __name__ == '__main__': | ||
| 229 | + main() | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,6 +25,7 @@ pathfix.py Change #!/usr/local/bin/python into something else | |||
| 25 | 25 | pdeps.py Print dependencies between Python modules | |
| 26 | 26 | pindent.py Indent Python code, giving block-closing comments | |
| 27 | 27 | ptags.py Create vi tags file for Python modules | |
| 28 | + pystone.py Benchmark, based on "Dhrystone" C benchmark | ||
| 28 | 29 | suff.py Sort a list of files by suffix | |
| 29 | 30 | sum5.py Print md5 checksums of files | |
| 30 | 31 | which.py Find a program in $PATH | |
| Back | FazBrowse Home | New Git URL |
0 commit comments