Message105455
Note that issue8425a.diff leaves small_set.difference_update(large_dict) unoptimized:
$ ./python.exe -m timeit -s "s = {1}; l = dict.fromkeys(range(1000));" "s.difference_update(l)"
1000 loops, best of 3: 842 usec per loop
$ ./python.exe -m timeit -s "s = {1}; l = dict.fromkeys(range(1000));" "s.difference(l)"
100000 loops, best of 3: 13.2 usec per loop
It would be easy to add an extra type check, but I noticed that small_set.difference_update(large_dict.viewkeys()) is not optimized either:
$ ./python.exe -m timeit -s "s = {1}; l = dict.fromkeys(range(1000));" "s.difference(l.viewkeys())"
1000 loops, best of 3: 842 usec per loop
It would be nice if there was a uniform C-API that would allow to uniformly check that an object supports O(1) lookup and invoke such lookup efficiently. I don't think such C-API exists at the moment.
I would like to hear what others have to say before adding optimizations to the patch that go beyond the scope of this issue. |
|
Date |
User |
Action |
Args |
2010-05-10 18:51:25 | belopolsky | set | recipients:
+ belopolsky, rhettinger, eric.smith, ezio.melotti, r.david.murray, abacabadabacaba |
2010-05-10 18:51:24 | belopolsky | set | messageid: <1273517484.93.0.347291477114.issue8425@psf.upfronthosting.co.za> |
2010-05-10 18:51:22 | belopolsky | link | issue8425 messages |
2010-05-10 18:51:22 | belopolsky | create | |
|