Which is faster?

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Thu Jan 27 03:52:21 CET 2005


Aggelos I. Orfanakos wrote:

> Any idea which of the following is faster?
> 
> 'a/b/c/'[:-1]
> 
> or
> 
> 'a/b/c/'.rstrip('/')
> 
> Thanks in advance.
> 
> P.S. I could time it but I thought of trying my luck here first, in
> case someone knows already, and of course the reason.

First, it almost certainly doesn't matter. Use the one that is
self-documenting.

Secondly, time it yourself. It's incredibly easy. There's a module
written especially for doing this - and surprise surprise, it's called
"timeit.py" and it's in the <python install location>/Lib directory.

Tim Delaney



More information about the Python-list mailing list