Why is checking isinstance(something, Mapping) so slow?
问题 I recently compared the performance of collections.Counter to sorted for comparison checks (if some iterable contains the same elements with the same amount) and while the big-iterable performance of Counter is generally better than sorted it's much slower for short iterables. Using line_profiler the bottleneck seems to be the isinstance(iterable, collections.Mapping) -check in Counter.update : %load_ext line_profiler # IPython lst = list(range(1000)) %lprun -f Counter.update Counter(lst)