mirror of
https://github.com/python/cpython.git
synced 2025-09-28 19:25:27 +00:00
merge
This commit is contained in:
commit
296b21a479
1 changed files with 28 additions and 18 deletions
|
@ -10,7 +10,10 @@
|
||||||
|
|
||||||
import time
|
import time
|
||||||
from math import log, ceil
|
from math import log, ceil
|
||||||
|
try:
|
||||||
from test.support import import_fresh_module
|
from test.support import import_fresh_module
|
||||||
|
except ImportError:
|
||||||
|
from test.test_support import import_fresh_module
|
||||||
|
|
||||||
C = import_fresh_module('decimal', fresh=['_decimal'])
|
C = import_fresh_module('decimal', fresh=['_decimal'])
|
||||||
P = import_fresh_module('decimal', blocked=['_decimal'])
|
P = import_fresh_module('decimal', blocked=['_decimal'])
|
||||||
|
@ -69,8 +72,12 @@ print("# ======================================================================\
|
||||||
|
|
||||||
for prec in [9, 19]:
|
for prec in [9, 19]:
|
||||||
print("\nPrecision: %d decimal digits\n" % prec)
|
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()
|
start = time.time()
|
||||||
|
if C is not None:
|
||||||
C.getcontext().prec = prec
|
C.getcontext().prec = prec
|
||||||
P.getcontext().prec = prec
|
P.getcontext().prec = prec
|
||||||
for i in range(10000):
|
for i in range(10000):
|
||||||
|
@ -84,6 +91,7 @@ print("\n# =====================================================================
|
||||||
print("# Factorial")
|
print("# Factorial")
|
||||||
print("# ======================================================================\n")
|
print("# ======================================================================\n")
|
||||||
|
|
||||||
|
if C is not None:
|
||||||
c = C.getcontext()
|
c = C.getcontext()
|
||||||
c.prec = C.MAX_PREC
|
c.prec = C.MAX_PREC
|
||||||
c.Emax = C.MAX_EMAX
|
c.Emax = C.MAX_EMAX
|
||||||
|
@ -93,6 +101,7 @@ for n in [100000, 1000000]:
|
||||||
|
|
||||||
print("n = %d\n" % n)
|
print("n = %d\n" % n)
|
||||||
|
|
||||||
|
if C is not None:
|
||||||
# C version of decimal
|
# C version of decimal
|
||||||
start_calc = time.time()
|
start_calc = time.time()
|
||||||
x = factorial(C.Decimal(n), 0)
|
x = factorial(C.Decimal(n), 0)
|
||||||
|
@ -116,4 +125,5 @@ for n in [100000, 1000000]:
|
||||||
print("calculation time: %fs" % (end_calc-start_calc))
|
print("calculation time: %fs" % (end_calc-start_calc))
|
||||||
print("conversion time: %fs\n\n" % (end_conv-start_conv))
|
print("conversion time: %fs\n\n" % (end_conv-start_conv))
|
||||||
|
|
||||||
|
if C is not None:
|
||||||
assert(sx == sy)
|
assert(sx == sy)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue