diff options
author | Stefan Krah <skrah@bytereef.org> | 2012-06-24 12:10:49 (GMT) |
---|---|---|
committer | Stefan Krah <skrah@bytereef.org> | 2012-06-24 12:10:49 (GMT) |
commit | 39e810eb6c6b19f3d8c26683c97207f411f0c22f (patch) | |
tree | 28e994247f7a267a74ce4c3067ff747b6d343b75 | |
parent | 6cff9ffab010e63a3a8cec6bf00513a557f085b2 (diff) | |
download | cpython-39e810eb6c6b19f3d8c26683c97207f411f0c22f.zip cpython-39e810eb6c6b19f3d8c26683c97207f411f0c22f.tar.gz cpython-39e810eb6c6b19f3d8c26683c97207f411f0c22f.tar.bz2 |
Make the benchmark more fair for _decimal/decimal.py by setting context.prec
only once (float obviously doesn't set any context at all).
-rw-r--r-- | 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 index ea0823a..01f851c 100644 --- a/Modules/_decimal/tests/bench.py +++ b/Modules/_decimal/tests/bench.py @@ -17,7 +17,7 @@ P = import_fresh_module('decimal', blocked=['_decimal']) # 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 @@ def pi_float(prec): 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 @@ def pi_cdecimal(prec): 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 @@ for prec in [9, 19]: 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)) |