Equivalent of Perl chomp?
Mark McEahern
marklists at mceahern.com
Thu Jan 31 16:33:49 EST 2002
Tim Peters wrote:
> Well, you're in for some fun of a kind I didn't have in mind <wink>. Do a
> sanity check here: what's the clock rate on your box? How many cycles go
> by in 0.07 seconds (let alone 0.36!)? Can you think of *any*
> non-insane way
> to implement these operations that would take so bloody long?
>
> I can't make time to explain timing subtleties today, but here's a hint:
> try swapping the order of your calls to endsWith and sliceIt, and see what
> you get then. If you hear your disk grinding <wink>, you might want to
> contemplate the sensibility of using a 100MB string.
I admit to being perfectly clueless about these subtleties, which I'm sure
my code only demonstrated all too abundantly. ;-)
Anyway, switching the order and trying the test again only leads to further
confusion:
<function sliceIt at 0x100f9510> : 0.00 seconds.
<function endsWith at 0x100f94d0> : 0.00 seconds.
And, when I switch the order back, I get the same thing:
<function endsWith at 0x100f94d0> : 0.00 seconds.
<function sliceIt at 0x100f9510> : 0.00 seconds.
Is it:
1) That using time.time() for timing is brain dead?
2) I'm using an unrealistically large string?
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 generally prefer the more legible approach and don't worry too much about
what's faster, but I thought I'd try to see whether these two different
approaches to endswith had a significant performance difference.
Cheers,
// mark
More information about the Python-list
mailing list