remove min() calls#589
Conversation
| return name.lower() in self._jump | ||
|
|
||
| def weekday(self, name): | ||
| if len(name) >= min(len(n) for n in self._weekdays.keys()): |
There was a problem hiding this comment.
This was recently added here, replacing a len(name) >= 3 check that was part of the original commit in this repo.
I think it was just there for performance reasons.
|
This is an unambigous win over the current code. To see what the best thing to do is, I made two versions, >>> i = parserinfo()
>>> i2 = parserinfo2()
>>> i3 = parserinfo3()
>>> %timeit i.weekday('Wed')
1000000 loops, best of 3: 627 ns per loop
>>> %timeit i2.weekday('Wed')
1000000 loops, best of 3: 393 ns per loop
>>> %timeit i3.weekday('Wed')
100000 loops, best of 3: 3.4 µs per loop
>>> %timeit i.weekday('A')
1000000 loops, best of 3: 285 ns per loop
>>> %timeit i2.weekday('A')
1000000 loops, best of 3: 724 ns per loop
>>> %timeit i3.weekday('A')
100000 loops, best of 3: 2.83 µs per loopWhen the string passed to I'm not sure all the code paths for the common case, but I'm guessing that it's actually kinda rare to hit the case where |
|
Yah, once we get to the point of trying to out-perform a dict lookup, it's time to go read a book. |
|
I suppose we could have done |
At least we can get something out of the adventure with asv. We can be fairly confident this is real because we saw cProfile results.