Profile Time on Wed Jul 15 01:13:11 2009
Reported Time on Mon May 24 21:55:08 2010

Profile Info

Profile Data Type: hotshot(line)
Total Time: 11.7962 CPU second
Total Func Call: 850004 function calls


Source Code   All functions data »

/usr/lib/python2.6/test/pystone.py
num      time      calls code
1
#! /usr/bin/python2.6
2
3
"""
4
"PYSTONE" Benchmark Program
5
6
Version:        Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)
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
Version History:
17
18
                Version 1.1 corrects two bugs in version 1.0:
19
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().
23
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.
32
33
"""
34
35
LOOPS = 50000
36
37
from time import clock
38
39
__version__ = "1.1"
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 0.07579 sec 75790 call
        self.PtrComp = PtrComp
48 0.074164 sec 74164 call
        self.Discr = Discr
49 0.072515 sec 72515 call
        self.EnumComp = EnumComp
50 0.071439 sec 71439 call
        self.IntComp = IntComp
51 0.072381 sec 72381 call
        self.StringComp = StringComp
52
53
    def copy(self):
54 0.06628 sec 66280 call
        return Record(self.PtrComp, self.Discr, self.EnumComp,
55 0.086205 sec 86205 call
                      self.IntComp, self.StringComp)
56
57
TRUE = 1
58
FALSE = 0
59
60
def main(loops=LOOPS):
61
    benchtime, stones = pystones(loops)
62
    print "Pystone(%s) time for %d passes = %g" % \
63
          (__version__, loops, benchtime)
64
    print "This machine benchmarks at %g pystones/second" % stones
65
66
67
def pystones(loops=LOOPS):
68 4e-06 sec 4 call
    return Proc0(loops)
69
70
IntGlob = 0
71
BoolGlob = FALSE
72
Char1Glob = '\0'
73
Char2Glob = '\0'
74
Array1Glob = [0]*51
75
Array2Glob = map(lambda x: x[:], [Array1Glob]*51)
76
PtrGlb = None
77
PtrGlbNext = None
78
79
def Proc0(loops=LOOPS):
80
    global IntGlob
81
    global BoolGlob
82
    global Char1Glob
83
    global Char2Glob
84
    global Array1Glob
85
    global Array2Glob
86
    global PtrGlb
87
    global PtrGlbNext
88
89 2e-06 sec 2 call
    starttime = clock()
90 0.084546 sec 84546 call
    for i in range(loops):
91 0.087031 sec 87031 call
        pass
92 0.001678 sec 1678 call
    nulltime = clock() - starttime
93
94 4.5e-05 sec 45 call
    PtrGlbNext = Record()
95 7e-06 sec 7 call
    PtrGlb = Record()
96 3e-06 sec 3 call
    PtrGlb.PtrComp = PtrGlbNext
97 3e-06 sec 3 call
    PtrGlb.Discr = Ident1
98 3e-06 sec 3 call
    PtrGlb.EnumComp = Ident3
99 2e-06 sec 2 call
    PtrGlb.IntComp = 40
100 2e-06 sec 2 call
    PtrGlb.StringComp = "DHRYSTONE PROGRAM, SOME STRING"
101 3e-06 sec 3 call
    String1Loc = "DHRYSTONE PROGRAM, 1'ST STRING"
102 3e-06 sec 3 call
    Array2Glob[8][7] = 10
103
104 5e-06 sec 5 call
    starttime = clock()
105
106 0.075148 sec 75148 call
    for i in range(loops):
107 0.078032 sec 78032 call
        Proc5()
108 0.075451 sec 75451 call
        Proc4()
109 0.07659 sec 76590 call
        IntLoc1 = 2
110 0.070806 sec 70806 call
        IntLoc2 = 3
111 0.071259 sec 71259 call
        String2Loc = "DHRYSTONE PROGRAM, 2'ND STRING"
112 0.07044 sec 70440 call
        EnumLoc = Ident2
113 0.072699 sec 72699 call
        BoolGlob = not Func2(String1Loc, String2Loc)
114 0.158409 sec 158409 call
        while IntLoc1 < IntLoc2:
115 0.077288 sec 77288 call
            IntLoc3 = 5 * IntLoc1 - IntLoc2
116 0.08092 sec 80920 call
            IntLoc3 = Proc7(IntLoc1, IntLoc2)
117 0.075995 sec 75995 call
            IntLoc1 = IntLoc1 + 1
118 0.085097 sec 85097 call
        Proc8(Array1Glob, Array2Glob, IntLoc1, IntLoc3)
119 0.080786 sec 80786 call
        PtrGlb = Proc1(PtrGlb)
120 0.081679 sec 81679 call
        CharIndex = 'A'
121 0.298286 sec 298286 call
        while CharIndex <= Char2Glob:
122 0.165313 sec 165313 call
            if EnumLoc == Func1(CharIndex, 'C'):
123
                EnumLoc = Proc6(Ident1)
124 0.17863 sec 178630 call
            CharIndex = chr(ord(CharIndex)+1)
125 0.0935900000001 sec 93590 call
        IntLoc3 = IntLoc2 * IntLoc1
126 0.079365 sec 79365 call
        IntLoc2 = IntLoc3 / IntLoc1
127 0.080392 sec 80392 call
        IntLoc2 = 7 * (IntLoc3 - IntLoc2) - IntLoc1
128 0.0872610000001 sec 87261 call
        IntLoc1 = Proc2(IntLoc1)
129
130 0.00072 sec 720 call
    benchtime = clock() - starttime - nulltime
131 8e-06 sec 8 call
    if benchtime == 0.0:
132
        loopsPerBenchtime = 0.0
133
    else:
134 3e-06 sec 3 call
        loopsPerBenchtime = (loops / benchtime)
135 3e-06 sec 3 call
    return benchtime, loopsPerBenchtime
136
137
def Proc1(PtrParIn):
138 0.066975 sec 66975 call
    PtrParIn.PtrComp = NextRecord = PtrGlb.copy()
139 0.08077 sec 80770 call
    PtrParIn.IntComp = 5
140 0.074597 sec 74597 call
    NextRecord.IntComp = PtrParIn.IntComp
141 0.081949 sec 81949 call
    NextRecord.PtrComp = PtrParIn.PtrComp
142 0.0936380000001 sec 93638 call
    NextRecord.PtrComp = Proc3(NextRecord.PtrComp)
143 0.076721 sec 76721 call
    if NextRecord.Discr == Ident1:
144 0.081096 sec 81096 call
        NextRecord.IntComp = 6
145 0.075298 sec 75298 call
        NextRecord.EnumComp = Proc6(PtrParIn.EnumComp)
146 0.07702 sec 77020 call
        NextRecord.PtrComp = PtrGlb.PtrComp
147 0.084167 sec 84167 call
        NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
148
    else:
149
        PtrParIn = NextRecord.copy()
150 0.07947 sec 79470 call
    NextRecord.PtrComp = None
151 0.075186 sec 75186 call
    return PtrParIn
152
153
def Proc2(IntParIO):
154 0.0671 sec 67100 call
    IntLoc = IntParIO + 10
155 0.072582 sec 72582 call
    while 1:
156 0.06851 sec 68510 call
        if Char1Glob == 'A':
157 0.074042 sec 74042 call
            IntLoc = IntLoc - 1
158 0.073135 sec 73135 call
            IntParIO = IntLoc - IntGlob
159 0.074005 sec 74005 call
            EnumLoc = Ident1
160 0.072331 sec 72331 call
        if EnumLoc == Ident1:
161 0.073998 sec 73998 call
            break
162 0.071644 sec 71644 call
    return IntParIO
163
164
def Proc3(PtrParOut):
165
    global IntGlob
166
167 0.072978 sec 72978 call
    if PtrGlb is not None:
168 0.075095 sec 75095 call
        PtrParOut = PtrGlb.PtrComp
169
    else:
170
        IntGlob = 100
171 0.078978 sec 78978 call
    PtrGlb.IntComp = Proc7(10, IntGlob)
172 0.076833 sec 76833 call
    return PtrParOut
173
174
def Proc4():
175
    global Char2Glob
176
177 0.074654 sec 74654 call
    BoolLoc = Char1Glob == 'A'
178 0.075263 sec 75263 call
    BoolLoc = BoolLoc or BoolGlob
179 0.070691 sec 70691 call
    Char2Glob = 'B'
180
181
def Proc5():
182
    global Char1Glob
183
    global BoolGlob
184
185 0.067084 sec 67084 call
    Char1Glob = 'A'
186 0.070377 sec 70377 call
    BoolGlob = FALSE
187
188
def Proc6(EnumParIn):
189 0.065786 sec 65786 call
    EnumParOut = EnumParIn
190 0.067535 sec 67535 call
    if not Func3(EnumParIn):
191
        EnumParOut = Ident4
192 0.077212 sec 77212 call
    if EnumParIn == Ident1:
193
        EnumParOut = Ident1
194 0.076108 sec 76108 call
    elif EnumParIn == Ident2:
195
        if IntGlob > 100:
196
            EnumParOut = Ident1
197
        else:
198
            EnumParOut = Ident4
199 0.075765 sec 75765 call
    elif EnumParIn == Ident3:
200 0.071831 sec 71831 call
        EnumParOut = Ident2
201
    elif EnumParIn == Ident4:
202
        pass
203
    elif EnumParIn == Ident5:
204
        EnumParOut = Ident3
205 0.072037 sec 72037 call
    return EnumParOut
206
207
def Proc7(IntParI1, IntParI2):
208 0.213506 sec 213506 call
    IntLoc = IntParI1 + 2
209 0.215984 sec 215984 call
    IntParOut = IntParI2 + IntLoc
210 0.213593 sec 213593 call
    return IntParOut
211
212
def Proc8(Array1Par, Array2Par, IntParI1, IntParI2):
213
    global IntGlob
214
215 0.074775 sec 74775 call
    IntLoc = IntParI1 + 5
216 0.072824 sec 72824 call
    Array1Par[IntLoc] = IntParI2
217 0.075669 sec 75669 call
    Array1Par[IntLoc+1] = Array1Par[IntLoc]
218 0.082388 sec 82388 call
    Array1Par[IntLoc+30] = IntLoc
219 0.239064 sec 239064 call
    for IntIndex in range(IntLoc, IntLoc+2):
220 0.188395 sec 188395 call
        Array2Par[IntLoc][IntIndex] = IntLoc
221 0.082063 sec 82063 call
    Array2Par[IntLoc][IntLoc-1] = Array2Par[IntLoc][IntLoc-1] + 1
222 0.0995170000001 sec 99517 call
    Array2Par[IntLoc+20][IntLoc] = Array1Par[IntLoc]
223 0.0952350000001 sec 95235 call
    IntGlob = 5
224
225
def Func1(CharPar1, CharPar2):
226 0.215248 sec 215248 call
    CharLoc1 = CharPar1
227 0.203587 sec 203587 call
    CharLoc2 = CharLoc1
228 0.204332 sec 204332 call
    if CharLoc2 != CharPar2:
229 0.216013 sec 216013 call
        return Ident1
230
    else:
231
        return Ident2
232
233
def Func2(StrParI1, StrParI2):
234 0.073888 sec 73888 call
    IntLoc = 1
235 0.143003 sec 143003 call
    while IntLoc <= 1:
236 0.074693 sec 74693 call
        if Func1(StrParI1[IntLoc], StrParI2[IntLoc+1]) == Ident1:
237 0.076421 sec 76421 call
            CharLoc = 'A'
238 0.07656 sec 76560 call
            IntLoc = IntLoc + 1
239 0.07762 sec 77620 call
    if CharLoc >= 'W' and CharLoc <= 'Z':
240
        IntLoc = 7
241 0.079049 sec 79049 call
    if CharLoc == 'X':
242
        return TRUE
243
    else:
244 0.077251 sec 77251 call
        if StrParI1 > StrParI2:
245
            IntLoc = IntLoc + 7
246
            return TRUE
247
        else:
248 0.079887 sec 79887 call
            return FALSE
249
250
def Func3(EnumParIn):
251 0.066506 sec 66506 call
    EnumLoc = EnumParIn
252
    if EnumLoc == Ident3: return TRUE
253
    return FALSE
254
255
if __name__ == '__main__':
256
    import sys
257
    def error(msg):
258
        print >>sys.stderr, msg,
259
        print >>sys.stderr, "usage: %s [number_of_loops]" % sys.argv[0]
260
        sys.exit(100)
261
    nargs = len(sys.argv) - 1
262
    if nargs > 1:
263
        error("%d arguments are too many;" % nargs)
264
    elif nargs == 1:
265
        try: loops = int(sys.argv[1])
266
        except ValueError:
267
            error("Invalid argument %r;" % sys.argv[1])
268
    else:
269
        loops = LOOPS
270
    main(loops)