On Tue, Dec 24, 2019 at 1:57 PM Kyle Stanley <aeros167@gmail.com> wrote:
Add (much faster for dicts):
timeit.timeit("s = set(); s.add(0)", number=100_000_000) 13.330938750001224 timeit.timeit("d = {}; d[0] = None", number=100_000_000) 5.788865385999088
I think this is an artifact of Python not having an empty set literal.
timeit.timeit("s = set(); s.add(0)", number=100_000_000) 13.275540543720126 timeit.timeit("d = dict(); d[0] = None", number=100_000_000) 13.044076398015022 timeit.timeit("d = {}; d[0] = None", number=100_000_000) 6.088695731014013 timeit.timeit("s = {1}; s.add(0)", number=100_000_000) 9.260965215042233 timeit.timeit("d = {1:2}; d[0] = None", number=100_000_000) 8.75433829985559
When both use the constructor call or both use a literal, the difference is far smaller. I'd call this one a wash. ChrisA