Working with decimals

Steven D'Aprano steve+comp.lang.python at pearwood.info
Sun Aug 24 22:16:26 EDT 2014


Joshua Landau wrote:


>>>> python -c "import sys; print('math' in sys.modules)"
> False
> 
> An even easier check:
> 
>>>> python -c "import time; a = time.time(); import math; b = time.time();
>>>> print(b-a)"
> 0.0006012916564941406
> 
>>>> python -c "import math, time; a = time.time(); import math; b =
>>>> time.time(); print(b-a)"
> 9.5367431640625e-06


I wouldn't exactly say that *two* calls to Python, each containing *five*
statements, followed by a visual comparison of two decimal numbers,
is "even easier" than a single call to Python, containing just two
statements :-)

Also, your timing test is open to interpretation and subject to interference
from the rest of your system, possibly even leading to completely the wrong
conclusion. If your system is sufficiently busy working on other tasks, the
two timings may be close together, or even reversed.


-- 
Steven




More information about the Python-list mailing list