[Python-checkins] cpython: Make the benchmark more fair for _decimal/decimal.py by setting context.prec
stefan.krah
python-checkins at python.org
Sun Jun 24 14:11:36 CEST 2012
http://hg.python.org/cpython/rev/fef58b80b7e0
changeset: 77707:fef58b80b7e0
user: Stefan Krah <skrah at bytereef.org>
date: Sun Jun 24 14:10:49 2012 +0200
summary:
Make the benchmark more fair for _decimal/decimal.py by setting context.prec
only once (float obviously doesn't set any context at all).
files:
Modules/_decimal/tests/bench.py | 12 ++++++------
1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/Modules/_decimal/tests/bench.py b/Modules/_decimal/tests/bench.py
--- a/Modules/_decimal/tests/bench.py
+++ b/Modules/_decimal/tests/bench.py
@@ -17,7 +17,7 @@
# Pi function from the decimal.py documentation
-def pi_float(prec):
+def pi_float():
"""native float"""
lasts, t, s, n, na, d, da = 0, 3.0, 3, 1, 0, 0, 24
while s != lasts:
@@ -28,9 +28,8 @@
s += t
return s
-def pi_cdecimal(prec):
+def pi_cdecimal():
"""cdecimal"""
- C.getcontext().prec = prec
D = C.Decimal
lasts, t, s, n, na, d, da = D(0), D(3), D(3), D(1), D(0), D(0), D(24)
while s != lasts:
@@ -41,9 +40,8 @@
s += t
return s
-def pi_decimal(prec):
+def pi_decimal():
"""decimal"""
- P.getcontext().prec = prec
D = P.Decimal
lasts, t, s, n, na, d, da = D(0), D(3), D(3), D(1), D(0), D(0), D(24)
while s != lasts:
@@ -73,8 +71,10 @@
print("\nPrecision: %d decimal digits\n" % prec)
for func in [pi_float, pi_cdecimal, pi_decimal]:
start = time.time()
+ C.getcontext().prec = prec
+ P.getcontext().prec = prec
for i in range(10000):
- x = func(prec)
+ x = func()
print("%s:" % func.__name__.replace("pi_", ""))
print("result: %s" % str(x))
print("time: %fs\n" % (time.time()-start))
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list