4 "PYSTONE" Benchmark Program
6 Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)
8 Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
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.
14 Translated from C to Python by Guido van Rossum.
18 Version 1.1 corrects two bugs in version 1.0:
20 First, it leaked memory: in Proc1(), NextRecord ends
21 up having a pointer to itself. I have corrected this
22 by zapping NextRecord.PtrComp at the end of Proc1().
24 Second, Proc3() used the operator != to compare a
25 record to None. This is rather inefficient and not
26 true to the intention of the original benchmark (where
27 a pointer comparison to None is intended; the !=
28 operator attempts to find a method __cmp__ to do value
29 comparison of the record). Version 1.1 runs 5-10
30 percent faster than version 1.0, so benchmark figures
31 of different versions can't be compared directly.
37 from time
import clock
41 [Ident1
, Ident2
, Ident3
, Ident4
, Ident5
] = range(1, 6)
45 def __init__(self
, PtrComp
= None, Discr
= 0, EnumComp
= 0,
46 IntComp
= 0, StringComp
= 0):
47 self
.PtrComp
= PtrComp
49 self
.EnumComp
= EnumComp
50 self
.IntComp
= IntComp
51 self
.StringComp
= StringComp
54 return Record(self
.PtrComp
, self
.Discr
, self
.EnumComp
,
55 self
.IntComp
, self
.StringComp
)
61 benchtime
, stones
= pystones()
62 print "Pystone(%s) time for %d passes = %g" % \
63 (__version__
, LOOPS
, benchtime
)
64 print "This machine benchmarks at %g pystones/second" % stones
67 def pystones(loops
=LOOPS
):
75 Array2Glob
= map(lambda x
: x
[:], [Array1Glob
]*51)
79 def Proc0(loops
=LOOPS
):
90 for i
in range(loops
):
92 nulltime
= clock() - starttime
96 PtrGlb
.PtrComp
= PtrGlbNext
98 PtrGlb
.EnumComp
= Ident3
100 PtrGlb
.StringComp
= "DHRYSTONE PROGRAM, SOME STRING"
101 String1Loc
= "DHRYSTONE PROGRAM, 1'ST STRING"
102 Array2Glob
[8][7] = 10
106 for i
in range(loops
):
111 String2Loc
= "DHRYSTONE PROGRAM, 2'ND STRING"
113 BoolGlob
= not Func2(String1Loc
, String2Loc
)
114 while IntLoc1
< IntLoc2
:
115 IntLoc3
= 5 * IntLoc1
- IntLoc2
116 IntLoc3
= Proc7(IntLoc1
, IntLoc2
)
117 IntLoc1
= IntLoc1
+ 1
118 Proc8(Array1Glob
, Array2Glob
, IntLoc1
, IntLoc3
)
119 PtrGlb
= Proc1(PtrGlb
)
121 while CharIndex
<= Char2Glob
:
122 if EnumLoc
== Func1(CharIndex
, 'C'):
123 EnumLoc
= Proc6(Ident1
)
124 CharIndex
= chr(ord(CharIndex
)+1)
125 IntLoc3
= IntLoc2
* IntLoc1
126 IntLoc2
= IntLoc3
/ IntLoc1
127 IntLoc2
= 7 * (IntLoc3
- IntLoc2
) - IntLoc1
128 IntLoc1
= Proc2(IntLoc1
)
130 benchtime
= clock() - starttime
- nulltime
131 return benchtime
, (loops
/ benchtime
)
134 PtrParIn
.PtrComp
= NextRecord
= PtrGlb
.copy()
136 NextRecord
.IntComp
= PtrParIn
.IntComp
137 NextRecord
.PtrComp
= PtrParIn
.PtrComp
138 NextRecord
.PtrComp
= Proc3(NextRecord
.PtrComp
)
139 if NextRecord
.Discr
== Ident1
:
140 NextRecord
.IntComp
= 6
141 NextRecord
.EnumComp
= Proc6(PtrParIn
.EnumComp
)
142 NextRecord
.PtrComp
= PtrGlb
.PtrComp
143 NextRecord
.IntComp
= Proc7(NextRecord
.IntComp
, 10)
145 PtrParIn
= NextRecord
.copy()
146 NextRecord
.PtrComp
= None
150 IntLoc
= IntParIO
+ 10
154 IntParIO
= IntLoc
- IntGlob
156 if EnumLoc
== Ident1
:
160 def Proc3(PtrParOut
):
163 if PtrGlb
is not None:
164 PtrParOut
= PtrGlb
.PtrComp
167 PtrGlb
.IntComp
= Proc7(10, IntGlob
)
173 BoolLoc
= Char1Glob
== 'A'
174 BoolLoc
= BoolLoc
or BoolGlob
184 def Proc6(EnumParIn
):
185 EnumParOut
= EnumParIn
186 if not Func3(EnumParIn
):
188 if EnumParIn
== Ident1
:
190 elif EnumParIn
== Ident2
:
195 elif EnumParIn
== Ident3
:
197 elif EnumParIn
== Ident4
:
199 elif EnumParIn
== Ident5
:
203 def Proc7(IntParI1
, IntParI2
):
204 IntLoc
= IntParI1
+ 2
205 IntParOut
= IntParI2
+ IntLoc
208 def Proc8(Array1Par
, Array2Par
, IntParI1
, IntParI2
):
211 IntLoc
= IntParI1
+ 5
212 Array1Par
[IntLoc
] = IntParI2
213 Array1Par
[IntLoc
+1] = Array1Par
[IntLoc
]
214 Array1Par
[IntLoc
+30] = IntLoc
215 for IntIndex
in range(IntLoc
, IntLoc
+2):
216 Array2Par
[IntLoc
][IntIndex
] = IntLoc
217 Array2Par
[IntLoc
][IntLoc
-1] = Array2Par
[IntLoc
][IntLoc
-1] + 1
218 Array2Par
[IntLoc
+20][IntLoc
] = Array1Par
[IntLoc
]
221 def Func1(CharPar1
, CharPar2
):
224 if CharLoc2
!= CharPar2
:
229 def Func2(StrParI1
, StrParI2
):
232 if Func1(StrParI1
[IntLoc
], StrParI2
[IntLoc
+1]) == Ident1
:
235 if CharLoc
>= 'W' and CharLoc
<= 'Z':
240 if StrParI1
> StrParI2
:
246 def Func3(EnumParIn
):
248 if EnumLoc
== Ident3
: return TRUE
251 if __name__
== '__main__':