<div dir="ltr">On 29 July 2013 07:25, Serhiy Storchaka <span dir="ltr"><<a href="mailto:storchaka@gmail.com" target="_blank">storchaka@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">28.07.13 22:59, Roy Smith написав(ла):<div class="im"><br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
  The input is an 8.8 Mbyte file containing about 570,000 lines (11,000<br>
unique strings).<br>
</blockquote>
<br></div>
Repeat you tests with totally unique lines.</blockquote><div><br></div><div>Counter is about ½ the speed of defaultdict in that case (as opposed to ⅓).</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
The full profiler dump is at the end of this message, but the gist of<br>
it is:<br>
</blockquote>
<br></div>
Profiler affects execution time. In particular it slowdown Counter implementation which uses more function calls. For real world measurement use different approach.</blockquote><div><br></div><div>Doing some re-times, it seems that his originals for defaultdict, exception and Counter were about right. I haven't timed the other.</div>

<div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div class="im">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
Why is count() [i.e. collections.Counter] so slow?<br>
</blockquote>
<br></div>
Feel free to contribute a patch which fixes this "wart". Note that Counter shouldn't be slowdowned on mostly unique data.</blockquote><div><br></div><div>I find it hard to agree that counter should be optimised for the unique-data case, as surely it's much more oft used when there's a point to counting?</div>

<div><br></div><div>Also, couldn't Counter just extend from defaultdict?</div></div></div></div>