Message386819
This only affects the contrived case of adding and removing exactly the same element in a tight loop, when the set is large. Optimizing that one corner case came at the expense of all other cases. The code is now simpler and slightly faster than before. This is also what we do for dictionaries.
$ python3.8 -m timeit -r 11 -s 's=set(range(10_000))' 'for i in range(10_000): (s.discard(i), s.add(10_000 - i))'
200 loops, best of 11: 1.72 msec per loop
$ python3.9 -m timeit -r 11 -s 's=set(range(10_000))' 'for i in range(10_000): (s.discard(i), s.add(10_000 - i))'
200 loops, best of 11: 1.09 msec per loop
Thank you for the report, but this was an intended change. |
|
Date |
User |
Action |
Args |
2021-02-11 05:40:22 | rhettinger | set | recipients:
+ rhettinger, zach.ware, eamartin, Dennis Sweeney |
2021-02-11 05:40:22 | rhettinger | set | messageid: <1613022022.13.0.947826571002.issue43198@roundup.psfhosted.org> |
2021-02-11 05:40:22 | rhettinger | link | issue43198 messages |
2021-02-11 05:40:22 | rhettinger | create | |
|