Skip to content

Instantly share code, notes, and snippets.

@elprans
Created Jan 26, 2018
Embed
What would you like to do?
bpo-32630 benchmark
$ envs/3.7-master-pgo-lto/prefix/bin/python3.7m ~/dev/python/cpython/Modules/_decimal/tests/bench.py
# ======================================================================
# Calculating pi, 10000 iterations
# ======================================================================
Precision: 9 decimal digits
float:
result: 3.1415926535897927
time: 0.048688s
cdecimal:
result: 3.14159265
time: 0.096675s
decimal:
result: 3.14159265
time: 8.458241s
Precision: 19 decimal digits
float:
result: 3.1415926535897927
time: 0.051486s
cdecimal:
result: 3.141592653589793236
time: 0.226973s
decimal:
result: 3.141592653589793236
time: 19.495910s
# ======================================================================
# Factorial
# ======================================================================
n = 100000
cdecimal:
calculation time: 0.356986s
conversion time: 0.001510s
int:
calculation time: 0.232633s
conversion time: 3.223236s
------------------------------------------------------------------------------------------------------------------------
$ envs/3.7-master-pgo+lto+decimal-contextvars/prefix/bin/python3.7m ~/dev/python/cpython/Modules/_decimal/tests/bench.py
# ======================================================================
# Calculating pi, 10000 iterations
# ======================================================================
Precision: 9 decimal digits
float:
result: 3.1415926535897927
time: 0.048424s
cdecimal:
result: 3.14159265
time: 0.100751s
decimal:
result: 3.14159265
time: 8.441837s
Precision: 19 decimal digits
float:
result: 3.1415926535897927
time: 0.049039s
cdecimal:
result: 3.141592653589793236
time: 0.227153s
decimal:
result: 3.141592653589793236
time: 19.353406s
# ======================================================================
# Factorial
# ======================================================================
n = 100000
cdecimal:
calculation time: 0.349761s
conversion time: 0.001494s
int:
calculation time: 0.236077s
conversion time: 3.224016s
@elprans
Copy link
Author

elprans commented Jan 26, 2018

vanilla:     0.096675s    0.226973s    0.356986s    0.001510s
contextvars: 0.100751s    0.227153s    0.349761s    0.001494s
-------------------------------------------------------------
             1.04x slower 1.00         1.02x faster 1.01x faster

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment