New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix adding functions to CommandChainDispatcher with equal priority on Py 3 #1932
Conversation
Code looks clean, running test_pr now |
Race you with the tests ;-) |
This looks solid, but just for my own edification, why use |
Test results for commit 2e28c7b merged into master
Not available for testing: python2.6 |
Test results for commit 2e28c7b merged into master
Not available for testing: python2.6, python3.1 |
I had the same thought as @minrk, decided not to really bring it up, but I also think the lambda in this case is cleaner than the rather awkward-looking itemgetter call. Order epsilon complaint, though :) I'm OK with it either way, otherwise I think this can go in. |
I understand that itemgetter is faster - not that it makes a jot of difference here, but just as general 'best practices'. On reflection, I think I'd actually prefer the lambda here as well. I'll commit that and then merge. |
Quick test shows it is a good deal faster: In [17]: import operator
In [18]: f = operator.itemgetter(0)
In [19]: g = lambda t: t[0]
In [20]: chain = [(i,'foo') for i in range(1000)]
In [21]: %timeit chain.sort(key=f)
10000 loops, best of 3: 163 us per loop
In [22]: %timeit chain.sort(key=g)
1000 loops, best of 3: 289 us per loop So almost twice as fast. But that's still only saving 0.1ms on a thousand items (already sorted). |
I guess it's the overhead of an repeatedly making an extra stack frame for the lambda - the operator module is compiled, so the sort can stay in C code. |
Fix adding functions to CommandChainDispatcher with equal priority on Py 3
Fix adding functions to CommandChainDispatcher with equal priority on Py 3
Includes a test.
Closes gh-1916