[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread Raymond Hettinger
Changes by Raymond Hettinger : Added file: http://bugs.python.org/file14399/tmp_time_missing.py ___ Python tracker ___ ___ Python-bugs-list mai

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread Raymond Hettinger
Changes by Raymond Hettinger : Removed file: http://bugs.python.org/file14391/tmp_time_missing.py ___ Python tracker ___ ___ Python-bugs-list m

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: I run many timings and the dict.get() approach is decidedly faster. Thanks for pointing that out. Applied in r73695, r73696, and 73697. FWIW, a timing suite is attached. -- resolution: -> fixed status: open -> closed versions: +Python 2.7, Python

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread SilentGhost
SilentGhost added the comment: I've never meant to suggest any kind of replacement of the Counter with my example. I just tried to show that self[elem] += 1# line 430 of collections.py which at initialisation naturally propagates to __missing__ is somewhat slow. and had it been possible t

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: Your proposed function assumes the input is a sequence and it cannot handle not a general purpose iterable (it gives the wrong answer when the latter is submitted). Also, it does two lookups per item which can be expensive if the elements have costly hash fu

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger nosy: +rhettinger priority: -> low ___ Python tracker ___ ___ Python-bugs-l

[issue6370] Bad performance of colllections.Counter at initialisation from an iterable

2009-06-29 Thread SilentGhost
New submission from SilentGhost : I'm comparing initialisation of Counter from an iterable with the following function: def unique(seq): """Dict of unique values (keys) & their counts in original sequence""" out_dict = dict.fromkeys(set(seq), 0) for i in seq: