by Terry Reed » Mon, 08 Aug 2005 07:38:24
"TPJ" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
Nothing in your results, properly interpreted, contradicts this.
On one machine, with one binary. Relative performance on different systems
can vary by, say, 10%. But of course, if you are optimizing a program to
run on just one machine, then the results on that machine are all that
matters.
To compare two things, one wants to remove all possible noise factors. If
one wants relative performance (ratios, percentages) then constant factors
should also be removed, when possible, to make the apparent difference as
close to the real difference as possible. Print is a large constant +
large noise factor that you *DO NOT* want for the stated comparison. It
requires a call through lots of OS code with variable execution times.
This is the right comparison for the reasons noted.
These times with print are about 300x the results below without print.
They are useless for comparing range and xrange. The differences above are
differences in printing (display) times and not in range versus xrange.
Think about it. When the differences between runs with print are several
times as large as the total time without, then those large differences
cannot have anything to do with the minor difference in looping method.
The looks more coherent.
You could, but you would be wrong. The second table shows that xrange is
slightly faster on your machine over the range tested.
This is completely backwards for the reasons already given. The point
about doing something inside loops in relevant in so far as it says the
that the minor difference between range and xrange, whichever way it goes
on a particular system, will matter relatively even less in application.
So the choice hardly matters unless space is a considerations. Which is
what the quoted docs more or less said.
To reduce random noise from random, the generator should be reinitialized
with the seed(someint) at the beginning of each function. This is the
purpose of seed(x). But for the comparisons you are making, randomness is
irrelevance and the time for calls to random a nuisance.
This is exactly what you DO NOT WANT TO DO for comparing anything else.
This is trivially different. To test 'l = []' versus 'del l[:]', test just
that.
It is not surprising that allocating a list just once and filling it in is
faster than starting empty and expanding and copying multiple times. In
any case, if you want to test that, test just that without all the noise
and masking of other stuff.
I did not look at the slicing stuff.
Terry J. Reedy