python : timeit - Tool for measuring execution time
Ben Finney
ben+python at benfinney.id.au
Wed Apr 22 01:52:41 EDT 2015
Ganesh Pal <ganesh1pal at gmail.com> writes:
> Iam running the below command on Linux machine have Python 2.7
> installed ,
If it hasn't already been said: You should be targeting Python 3
wherever possible (with the ‘python3’ command).
Since you're not in this case – and you are specifically testing Python
2 features – you should get used to invoking Python 2 specifically, with
the ‘python2’ command.
> I was trying to figure out the speed difference between xrange and
> range functions.
This is the right way to do it. Thank you for actually measuring
specific performance!
> 10 loops, best of 3: 51.1 msec per loop
>
> Iam not able to understand what why only 10 loops were run ?
What behaviour did you expect? You didn't ask for any particular number
of iterations, so you've allowed the tool to choose for you
<URL:https://docs.python.org/3/library/timeit.html#cmdoption-timeit-n>.
The documentation for the ‘timeit’ module specifies what happens when
you omit the “number of iterations” parameter:
If -n is not given, a suitable number of loops is calculated by
trying successive powers of 10 until the total time is at least 0.2
seconds.
> what does this mean and how does this work ?
I don't know what such a vague question means. Can you read the
documentation and ask some more specific question?
--
\ “Oh, I love your magazine. My favorite section is ‘How To |
`\ Increase Your Word Power’. That thing is really, really, |
_o__) really... good.” —Homer, _The Simpsons_ |
Ben Finney
More information about the Python-list
mailing list