Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/pystone.py @ 5817:48b94de85bf3 legacy-trunk
Extensive changes by AMK.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Thu, 17 Jul 1997 16:29:42 +0000 |
| parents | 17c7a133ccf7 |
| children | 6c449dff2fb8 |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
2613
diff
changeset
|
1 #! /usr/bin/env python |
| 2613 | 2 |
| 3 """ | |
| 4 "PYSTONE" Benchmark Program | |
| 5 | |
|
5001
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
6 Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes) |
| 2613 | 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. | |
|
5001
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
15 |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
16 Version History: |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
17 |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
18 Version 1.1 corrects two bugs in version 1.0: |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
19 |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
20 First, it leaked memory: in Proc1(), NextRecord ends |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
21 up having a pointer to itself. I have corrected this |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
22 by zapping NextRecord.PtrComp at the end of Proc1(). |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
23 |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
24 Second, Proc3() used the operator != to compare a |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
25 record to None. This is rather inefficient and not |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
26 true to the intention of the original benchmark (where |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
27 a pointer comparison to None is intended; the != |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
28 operator attempts to find a method __cmp__ to do value |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
29 comparison of the record). Version 1.1 runs 5-10 |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
30 percent faster than version 1.0, so benchmark figures |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
31 of different versions can't be compared directly. |
|
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
32 |
| 2613 | 33 """ |
| 34 | |
| 35 LOOPS = 1000 | |
| 36 | |
| 37 from time import clock | |
| 38 | |
|
5001
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
39 __version__ = "1.1" |
| 2613 | 40 |
| 41 [Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6) | |
| 42 | |
| 43 class Record: | |
| 44 | |
| 45 def __init__(self, PtrComp = None, Discr = 0, EnumComp = 0, | |
| 46 IntComp = 0, StringComp = 0): | |
| 47 self.PtrComp = PtrComp | |
| 48 self.Discr = Discr | |
| 49 self.EnumComp = EnumComp | |
| 50 self.IntComp = IntComp | |
| 51 self.StringComp = StringComp | |
| 52 | |
| 53 def copy(self): | |
| 54 return Record(self.PtrComp, self.Discr, self.EnumComp, | |
| 55 self.IntComp, self.StringComp) | |
| 56 | |
| 57 TRUE = 1 | |
| 58 FALSE = 0 | |
| 59 | |
| 60 def main(): | |
| 61 Proc0() | |
| 62 | |
| 63 IntGlob = 0 | |
| 64 BoolGlob = FALSE | |
| 65 Char1Glob = '\0' | |
| 66 Char2Glob = '\0' | |
| 67 Array1Glob = [0]*51 | |
| 68 Array2Glob = map(lambda x: x[:], [Array1Glob]*51) | |
| 69 PtrGlb = None | |
| 70 PtrGlbNext = None | |
| 71 | |
| 72 def Proc0(): | |
| 73 global IntGlob | |
| 74 global BoolGlob | |
| 75 global Char1Glob | |
| 76 global Char2Glob | |
| 77 global Array1Glob | |
| 78 global Array2Glob | |
| 79 global PtrGlb | |
| 80 global PtrGlbNext | |
| 81 | |
| 82 starttime = clock() | |
| 83 for i in range(LOOPS): | |
| 84 pass | |
| 85 nulltime = clock() - starttime | |
| 86 | |
| 87 PtrGlbNext = Record() | |
| 88 PtrGlb = Record() | |
| 89 PtrGlb.PtrComp = PtrGlbNext | |
| 90 PtrGlb.Discr = Ident1 | |
| 91 PtrGlb.EnumComp = Ident3 | |
| 92 PtrGlb.IntComp = 40 | |
| 93 PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING" | |
| 94 String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING" | |
| 95 Array2Glob[8][7] = 10 | |
| 96 | |
| 97 starttime = clock() | |
| 98 | |
| 99 for i in range(LOOPS): | |
| 100 Proc5() | |
| 101 Proc4() | |
| 102 IntLoc1 = 2 | |
| 103 IntLoc2 = 3 | |
| 104 String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING" | |
| 105 EnumLoc = Ident2 | |
| 106 BoolGlob = not Func2(String1Loc, String2Loc) | |
| 107 while IntLoc1 < IntLoc2: | |
| 108 IntLoc3 = 5 * IntLoc1 - IntLoc2 | |
| 109 IntLoc3 = Proc7(IntLoc1, IntLoc2) | |
| 110 IntLoc1 = IntLoc1 + 1 | |
| 111 Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3) | |
| 112 PtrGlb = Proc1(PtrGlb) | |
| 113 CharIndex = 'A' | |
| 114 while CharIndex <= Char2Glob: | |
| 115 if EnumLoc == Func1(CharIndex, 'C'): | |
| 116 EnumLoc = Proc6(Ident1) | |
| 117 CharIndex = chr(ord(CharIndex)+1) | |
| 118 IntLoc3 = IntLoc2 * IntLoc1 | |
| 119 IntLoc2 = IntLoc3 / IntLoc1 | |
| 120 IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1 | |
| 121 IntLoc1 = Proc2(IntLoc1) | |
| 122 | |
| 123 benchtime = clock() - starttime - nulltime | |
| 124 print "Pystone(%s) time for %d passes = %g" % \ | |
| 125 (__version__, LOOPS, benchtime) | |
| 126 print "This machine benchmarks at %g pystones/second" % \ | |
| 127 (LOOPS/benchtime) | |
| 128 | |
| 129 def Proc1(PtrParIn): | |
| 130 PtrParIn.PtrComp = NextRecord = PtrGlb.copy() | |
| 131 PtrParIn.IntComp = 5 | |
| 132 NextRecord.IntComp = PtrParIn.IntComp | |
| 133 NextRecord.PtrComp = PtrParIn.PtrComp | |
| 134 NextRecord.PtrComp = Proc3(NextRecord.PtrComp) | |
| 135 if NextRecord.Discr == Ident1: | |
| 136 NextRecord.IntComp = 6 | |
| 137 NextRecord.EnumComp = Proc6(PtrParIn.EnumComp) | |
| 138 NextRecord.PtrComp = PtrGlb.PtrComp | |
| 139 NextRecord.IntComp = Proc7(NextRecord.IntComp, 10) | |
| 140 else: | |
| 141 PtrParIn = NextRecord.copy() | |
|
5001
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
142 NextRecord.PtrComp = None |
| 2613 | 143 return PtrParIn |
| 144 | |
| 145 def Proc2(IntParIO): | |
| 146 IntLoc = IntParIO + 10 | |
| 147 while 1: | |
| 148 if Char1Glob == 'A': | |
| 149 IntLoc = IntLoc - 1 | |
| 150 IntParIO = IntLoc - IntGlob | |
| 151 EnumLoc = Ident1 | |
| 152 if EnumLoc == Ident1: | |
| 153 break | |
| 154 return IntParIO | |
| 155 | |
| 156 def Proc3(PtrParOut): | |
| 157 global IntGlob | |
| 158 | |
|
5001
17c7a133ccf7
Version 1.1. Fix memory leak and expensive comparison with None.
Guido van Rossum <guido@python.org>
parents:
4573
diff
changeset
|
159 if PtrGlb is not None: |
| 2613 | 160 PtrParOut = PtrGlb.PtrComp |
| 161 else: | |
| 162 IntGlob = 100 | |
| 163 PtrGlb.IntComp = Proc7(10, IntGlob) | |
| 164 return PtrParOut | |
| 165 | |
| 166 def Proc4(): | |
| 167 global Char2Glob | |
| 168 | |
| 169 BoolLoc = Char1Glob == 'A' | |
| 170 BoolLoc = BoolLoc or BoolGlob | |
| 171 Char2Glob = 'B' | |
| 172 | |
| 173 def Proc5(): | |
| 174 global Char1Glob | |
| 175 global BoolGlob | |
| 176 | |
| 177 Char1Glob = 'A' | |
| 178 BoolGlob = FALSE | |
| 179 | |
| 180 def Proc6(EnumParIn): | |
| 181 EnumParOut = EnumParIn | |
| 182 if not Func3(EnumParIn): | |
| 183 EnumParOut = Ident4 | |
| 184 if EnumParIn == Ident1: | |
| 185 EnumParOut = Ident1 | |
| 186 elif EnumParIn == Ident2: | |
| 187 if IntGlob > 100: | |
| 188 EnumParOut = Ident1 | |
| 189 else: | |
| 190 EnumParOut = Ident4 | |
| 191 elif EnumParIn == Ident3: | |
| 192 EnumParOut = Ident2 | |
| 193 elif EnumParIn == Ident4: | |
| 194 pass | |
| 195 elif EnumParIn == Ident5: | |
| 196 EnumParOut = Ident3 | |
| 197 return EnumParOut | |
| 198 | |
| 199 def Proc7(IntParI1, IntParI2): | |
| 200 IntLoc = IntParI1 + 2 | |
| 201 IntParOut = IntParI2 + IntLoc | |
| 202 return IntParOut | |
| 203 | |
| 204 def Proc8(Array1Par, Array2Par, IntParI1, IntParI2): | |
| 205 global IntGlob | |
| 206 | |
| 207 IntLoc = IntParI1 + 5 | |
| 208 Array1Par[IntLoc] = IntParI2 | |
| 209 Array1Par[IntLoc+1] = Array1Par[IntLoc] | |
| 210 Array1Par[IntLoc+30] = IntLoc | |
| 211 for IntIndex in range(IntLoc, IntLoc+2): | |
| 212 Array2Par[IntLoc][IntIndex] = IntLoc | |
| 213 Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1 | |
| 214 Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc] | |
| 215 IntGlob = 5 | |
| 216 | |
| 217 def Func1(CharPar1, CharPar2): | |
| 218 CharLoc1 = CharPar1 | |
| 219 CharLoc2 = CharLoc1 | |
| 220 if CharLoc2 != CharPar2: | |
| 221 return Ident1 | |
| 222 else: | |
| 223 return Ident2 | |
| 224 | |
| 225 def Func2(StrParI1, StrParI2): | |
| 226 IntLoc = 1 | |
| 227 while IntLoc <= 1: | |
| 228 if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1: | |
| 229 CharLoc = 'A' | |
| 230 IntLoc = IntLoc + 1 | |
| 231 if CharLoc >= 'W' and CharLoc <= 'Z': | |
| 232 IntLoc = 7 | |
| 233 if CharLoc == 'X': | |
| 234 return TRUE | |
| 235 else: | |
| 236 if StrParI1 > StrParI2: | |
| 237 IntLoc = IntLoc + 7 | |
| 238 return TRUE | |
| 239 else: | |
| 240 return FALSE | |
| 241 | |
| 242 def Func3(EnumParIn): | |
| 243 EnumLoc = EnumParIn | |
| 244 if EnumLoc == Ident3: return TRUE | |
| 245 return FALSE | |
| 246 | |
| 247 if __name__ == '__main__': | |
| 248 main() |
