Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 04f2b45

Browse files
committed
Version 1.1. Fix memory leak and expensive comparison with None.
1 parent 3e7ae7a commit 04f2b45

2 files changed

Lines changed: 44 additions & 6 deletions

File tree

Lib/test/pystone.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
"PYSTONE" Benchmark Program
55
6-
Version: Python/1.0 (corresponds to C/1.1)
6+
Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)
77
88
Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
99
@@ -12,13 +12,31 @@
1212
at the expense of C-ness.
1313
1414
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+
1533
"""
1634

1735
LOOPS = 1000
1836

1937
from time import clock
2038

21-
__version__ = "1.0"
39+
__version__ = "1.1"
2240

2341
[Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6)
2442

@@ -121,6 +139,7 @@ def Proc1(PtrParIn):
121139
NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
122140
else:
123141
PtrParIn = NextRecord.copy()
142+
NextRecord.PtrComp = None
124143
return PtrParIn
125144

126145
def Proc2(IntParIO):
@@ -137,7 +156,7 @@ def Proc2(IntParIO):
137156
def Proc3(PtrParOut):
138157
global IntGlob
139158

140-
if PtrGlb != None:
159+
if PtrGlb is not None:
141160
PtrParOut = PtrGlb.PtrComp
142161
else:
143162
IntGlob = 100

Tools/scripts/pystone.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"""
44
"PYSTONE" Benchmark Program
55
6-
Version: Python/1.0 (corresponds to C/1.1)
6+
Version: Python/1.1 (corresponds to C/1.1 plus 2 Pystone fixes)
77
88
Author: Reinhold P. Weicker, CACM Vol 27, No 10, 10/84 pg. 1013.
99
@@ -12,13 +12,31 @@
1212
at the expense of C-ness.
1313
1414
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+
1533
"""
1634

1735
LOOPS = 1000
1836

1937
from time import clock
2038

21-
__version__ = "1.0"
39+
__version__ = "1.1"
2240

2341
[Ident1, Ident2, Ident3, Ident4, Ident5] = range(1, 6)
2442

@@ -121,6 +139,7 @@ def Proc1(PtrParIn):
121139
NextRecord.IntComp = Proc7(NextRecord.IntComp, 10)
122140
else:
123141
PtrParIn = NextRecord.copy()
142+
NextRecord.PtrComp = None
124143
return PtrParIn
125144

126145
def Proc2(IntParIO):
@@ -137,7 +156,7 @@ def Proc2(IntParIO):
137156
def Proc3(PtrParOut):
138157
global IntGlob
139158

140-
if PtrGlb != None:
159+
if PtrGlb is not None:
141160
PtrParOut = PtrGlb.PtrComp
142161
else:
143162
IntGlob = 100

0 commit comments

Comments
 (0)