[Python-checkins] cpython (merge default -> default): merge

barry.warsaw python-checkins at python.org
Tue Sep 25 16:48:40 CEST 2012


http://hg.python.org/cpython/rev/e4e7cca4dc39
changeset:   79168:e4e7cca4dc39
parent:      79167:cce2bfe03dc5
parent:      79164:6948debfaa19
user:        Barry Warsaw <barry at python.org>
date:        Tue Sep 25 10:48:25 2012 -0400
summary:
  merge

files:
  Modules/_decimal/tests/bench.py |  46 ++++++++++++--------
  1 files changed, 28 insertions(+), 18 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
@@ -10,7 +10,10 @@
 
 import time
 from math import log, ceil
-from test.support import import_fresh_module
+try:
+    from test.support import import_fresh_module
+except ImportError:
+    from test.test_support import import_fresh_module
 
 C = import_fresh_module('decimal', fresh=['_decimal'])
 P = import_fresh_module('decimal', blocked=['_decimal'])
@@ -69,9 +72,13 @@
 
 for prec in [9, 19]:
     print("\nPrecision: %d decimal digits\n" % prec)
-    for func in [pi_float, pi_cdecimal, pi_decimal]:
+    to_benchmark = [pi_float, pi_decimal]
+    if C is not None:
+        to_benchmark.append(pi_cdecimal)
+    for func in to_benchmark:
         start = time.time()
-        C.getcontext().prec = prec
+        if C is not None:
+            C.getcontext().prec = prec
         P.getcontext().prec = prec
         for i in range(10000):
             x = func()
@@ -84,25 +91,27 @@
 print("#                               Factorial")
 print("# ======================================================================\n")
 
-c = C.getcontext()
-c.prec = C.MAX_PREC
-c.Emax = C.MAX_EMAX
-c.Emin = C.MIN_EMIN
+if C is not None:
+    c = C.getcontext()
+    c.prec = C.MAX_PREC
+    c.Emax = C.MAX_EMAX
+    c.Emin = C.MIN_EMIN
 
 for n in [100000, 1000000]:
 
     print("n = %d\n" % n)
 
-    # C version of decimal
-    start_calc = time.time()
-    x = factorial(C.Decimal(n), 0)
-    end_calc = time.time()
-    start_conv = time.time()
-    sx = str(x)
-    end_conv = time.time()
-    print("cdecimal:")
-    print("calculation time: %fs" % (end_calc-start_calc))
-    print("conversion time: %fs\n" % (end_conv-start_conv))
+    if C is not None:
+        # C version of decimal
+        start_calc = time.time()
+        x = factorial(C.Decimal(n), 0)
+        end_calc = time.time()
+        start_conv = time.time()
+        sx = str(x)
+        end_conv = time.time()
+        print("cdecimal:")
+        print("calculation time: %fs" % (end_calc-start_calc))
+        print("conversion time: %fs\n" % (end_conv-start_conv))
 
     # Python integers
     start_calc = time.time()
@@ -116,4 +125,5 @@
     print("calculation time: %fs" % (end_calc-start_calc))
     print("conversion time: %fs\n\n" % (end_conv-start_conv))
 
-    assert(sx == sy)
+    if C is not None:
+        assert(sx == sy)

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list