1 #! /usr/local/bin/python
4 "PYSTONE" Benchmark Program
6 Version: Python/1.0 (corresponds to C/1.1)
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.
19 from time
import clock
23 [Ident1
, Ident2
, Ident3
, Ident4
, Ident5
] = range(1, 6)
27 def __init__(self
, PtrComp
= None, Discr
= 0, EnumComp
= 0,
28 IntComp
= 0, StringComp
= 0):
29 self
.PtrComp
= PtrComp
31 self
.EnumComp
= EnumComp
32 self
.IntComp
= IntComp
33 self
.StringComp
= StringComp
36 return Record(self
.PtrComp
, self
.Discr
, self
.EnumComp
,
37 self
.IntComp
, self
.StringComp
)
50 Array2Glob
= map(lambda x
: x
[:], [Array1Glob
]*51)
65 for i
in range(LOOPS
):
67 nulltime
= clock() - starttime
71 PtrGlb
.PtrComp
= PtrGlbNext
73 PtrGlb
.EnumComp
= Ident3
75 PtrGlb
.StringComp
= "DHRYSTONE PROGRAM, SOME STRING"
76 String1Loc
= "DHRYSTONE PROGRAM, 1'ST STRING"
81 for i
in range(LOOPS
):
86 String2Loc
= "DHRYSTONE PROGRAM, 2'ND STRING"
88 BoolGlob
= not Func2(String1Loc
, String2Loc
)
89 while IntLoc1
< IntLoc2
:
90 IntLoc3
= 5 * IntLoc1
- IntLoc2
91 IntLoc3
= Proc7(IntLoc1
, IntLoc2
)
93 Proc8(Array1Glob
, Array2Glob
, IntLoc1
, IntLoc3
)
94 PtrGlb
= Proc1(PtrGlb
)
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
)
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" % \
112 PtrParIn
.PtrComp
= NextRecord
= PtrGlb
.copy()
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)
123 PtrParIn
= NextRecord
.copy()
127 IntLoc
= IntParIO
+ 10
131 IntParIO
= IntLoc
- IntGlob
133 if EnumLoc
== Ident1
:
137 def Proc3(PtrParOut
):
141 PtrParOut
= PtrGlb
.PtrComp
144 PtrGlb
.IntComp
= Proc7(10, IntGlob
)
150 BoolLoc
= Char1Glob
== 'A'
151 BoolLoc
= BoolLoc
or BoolGlob
161 def Proc6(EnumParIn
):
162 EnumParOut
= EnumParIn
163 if not Func3(EnumParIn
):
165 if EnumParIn
== Ident1
:
167 elif EnumParIn
== Ident2
:
172 elif EnumParIn
== Ident3
:
174 elif EnumParIn
== Ident4
:
176 elif EnumParIn
== Ident5
:
180 def Proc7(IntParI1
, IntParI2
):
181 IntLoc
= IntParI1
+ 2
182 IntParOut
= IntParI2
+ IntLoc
185 def Proc8(Array1Par
, Array2Par
, IntParI1
, IntParI2
):
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
]
198 def Func1(CharPar1
, CharPar2
):
201 if CharLoc2
!= CharPar2
:
206 def Func2(StrParI1
, StrParI2
):
209 if Func1(StrParI1
[IntLoc
], StrParI2
[IntLoc
+1]) == Ident1
:
212 if CharLoc
>= 'W' and CharLoc
<= 'Z':
217 if StrParI1
> StrParI2
:
223 def Func3(EnumParIn
):
225 if EnumLoc
== Ident3
: return TRUE
228 if __name__
== '__main__':