On my single core 1.4 GHz computer, I ran the following 2 timeit codes:
suzan:~$ python -mtimeit "
def count(n):
while n > 0:
n -= 1
count(10000000)
"
10 loops, best of 3: 1.73 sec per loop
suzan:~$
suzan:~$ python -mtimeit "
import os
def count(n):
while n > 0:
n -= 1
count(10000000)
"
10 loops, best of 3: 1.18 sec per loop
suzan:~$
The second timeit command show lesser time than the first one, even when it contains one extra line of code "import os". Is this unusual behavior or the expected one ?
Any help is greatly appreciated.