Equivalent of Perl chomp?

Nicholas FitzRoy-Dale wzdd at lardcave.net
Thu Jan 31 18:23:43 EST 2002


On Thu, 31 Jan 2002, Mark McEahern wrote:

> Tim, is your point that the performance difference in normal cases is
> negligible?  If so, I would guess the further point would be to choose
> endswith() because it's more legible.

I think there are two issues that Tim is referring to:
	1) time.time() is too low-resolution to accurately measure a single
event, and
	2) When you run the program, you must take into account a "cold"
swap space, meaning that the first run of the program will be slower than
subsequent runs.

To avoid these things, it's best to run your test multiple times:

startTime=time.time()
for count in xrange (100000):
	testString.endswith('a')
print time.time()-startTime

Also run your program multiple times. To be thorough, run your program
multiple times, swap the order of the tests, and then run the new, swapped
program multiple times.

- Nicholas FitzRoy-Dale






More information about the Python-list mailing list