Equivalent of Perl chomp?
Steve Holden
sholden at holdenweb.com
Fri Feb 1 13:34:22 EST 2002
"Tim Peters" <tim.one at home.com> wrote in message
news:mailman.1012521782.11272.python-list at python.org...
> Now that Steve Holden has determined sliceIt is quicker than endsWith in a
> semi-believable <wink> way, note the timings his program gives are the
same
> whether the string is of length 1000000 or 100 (provided you have enough
> RAM). For even more fun, see what happens if you check for a 2-character
> suffix instead of a 1-character suffix. Hmm! In either case, how much of
> the difference is due to what endswith *does*, and how much is due to the
> overhead of simply building the s.endswith bound method object?
>
> there's-no-end-to-this-kind-of-fun-ly y'rs - tim
>
1,000,000 iterations.
Testing for length 1:
Endswith 0.00000505
sliceIt 0.00000209
Testing for length 2:
Endswith 0.00001137
sliceIt 0.00001148
Length 3:
Endswith 0.00001055 [!]
sliceIt 0.00001264
Of course, these tests are with the tests succeeding. I'm presuming failure
would shorten the timings, but I'm not going to bother checking that
assumption.
semi-believab-ly y'rs - steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/
More information about the Python-list
mailing list