MCPcopy Index your code
hub / github.com/python/cpython / test_factorial

Function test_factorial

Modules/_decimal/tests/bench.py:106–146  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

104
105@increase_int_max_str_digits(maxdigits=10000000)
106def test_factorial():
107 print("\n# ======================================================================")
108 print("# Factorial")
109 print("# ======================================================================\n")
110
111 if C is not None:
112 c = C.getcontext()
113 c.prec = C.MAX_PREC
114 c.Emax = C.MAX_EMAX
115 c.Emin = C.MIN_EMIN
116
117 for n in [100000, 1000000]:
118
119 print("n = %d\n" % n)
120
121 if C is not None:
122 # C version of decimal
123 start_calc = time.time()
124 x = factorial(C.Decimal(n), 0)
125 end_calc = time.time()
126 start_conv = time.time()
127 sx = str(x)
128 end_conv = time.time()
129 print("cdecimal:")
130 print("calculation time: %fs" % (end_calc-start_calc))
131 print("conversion time: %fs\n" % (end_conv-start_conv))
132
133 # Python integers
134 start_calc = time.time()
135 y = factorial(n, 0)
136 end_calc = time.time()
137 start_conv = time.time()
138 sy = str(y)
139 end_conv = time.time()
140
141 print("int:")
142 print("calculation time: %fs" % (end_calc-start_calc))
143 print("conversion time: %fs\n\n" % (end_conv-start_conv))
144
145 if C is not None:
146 assert(sx == sy)
147
148if __name__ == "__main__":
149 test_calc_pi()

Callers 1

bench.pyFile · 0.85

Calls 3

strFunction · 0.85
factorialFunction · 0.70
timeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…