Surely the best choice is two have *two* caches; one for hashables and another for the rest.<div><br></div><div>This might be improvable with a *third* chache if some non-hashables had total ordering, but that could also introduce bugs I think. It'd also be a lot harder and likely be slower anyway.</div>
<div><br></div><div>Timings (approximate and rough):</div><div>"""</div><div><div>Using 16 elements</div><div><br></div><div>% Hashable: 100 90 66 33 0</div><div>Original: 1.47 1.00 1.06 1.09 1.01</div>
<div>w/ key=str: 3.73 1.91 2.12 3.15 3.00</div><div>New: 1.20 1.46 1.81 2.13 3.38</div><div>w/ key=str: 1.72 2.00 2.48 2.76 3.01</div><div><br></div><div>Using 64 elements</div><div><br>
</div><div>% Hashable: 100 90 66 33 0</div><div>Original: 1.15 1.29 1.61 1.64 1.43</div><div>w/ key=str: 1.98 2.50 3.09 3.55 3.99</div><div>New: 1.00 1.47 2.18 3.01 3.60</div>
<div>w/ key=str: 1.87 2.30 2.79 3.41 3.84</div><div><br></div><div>Using 256 elements</div><div><br></div><div>% Hashable: 100 90 66 33 0</div><div>Original: 2.70 3.66 5.19 5.34 4.41</div>
<div>w/ key=str: 4.06 5.07 6.26 6.93 6.98</div><div>New: 1.00 1.65 2.92 5.28 7.62</div><div>w/ key=str: 2.28 2.71 3.76 4.36 4.93</div><div><br></div><div>Using 1024 elements</div><div>
<br></div><div>% Hashable: 100 90 66 33 0</div><div>Original: 9.30 12.4 18.8 21.4 16.9</div><div>w/ key=str: 11.1 13.1 16.3 17.5 13.9</div><div>New: 1.00 1.84 6.20 13.1 19.8</div>
<div>w/ key=str: 2.31 2.79 3.59 4.50 5.16</div><div><br></div><div>Using 4096 elements</div><div><br></div><div>% Hashable: 100 90 66 33 0</div><div>Original: 33.7 44.3 69.1 79.4 60.5</div>
<div>w/ key=str: 36.7 44.2 59.3 60.1 40.4</div><div>New: 1.00 3.73 18.1 42.2 63.7</div><div>w/ key=str: 2.23 2.56 3.33 4.19 4.93</div><div><br></div><div>Using 16384 elements</div><div>
<br></div><div>% Hashable: 100 90 66 33 0</div><div>Original: 126. 173. 265. 313. 243.</div><div>w/ key=str: 136. 164. 215. 213. 147.</div><div>New: 1.00 12.5 68.6 173. 263.</div>
<div>w/ key=str: 2.24 2.60 3.28 4.14 4.80</div></div><div>"""</div><div><br></div><div>--------------</div><div><br></div><div>Code attached, unless I forget ;).</div><div>No guarantees that it still works the same way, or works at all, or is the right file.</div>
<div><br></div><div>Every item is repeated 5 times on average for any length of the list being unique-ified. I'll try it with this changed later.</div><div><br></div><div>Basically, the new version is faster on all but ~100% non-hashable lists when there are more than ~1000 elements, and on more-hashable lists it's quadratically faster. When slower, it's by only about 10% to 20%. Of course, specifying whether or not your list is fully-hashable would be more efficient (probably 10%) but that's not as nice to use.</div>
<div><br></div><div>Additionally, if you use key="" to uniquify by hashable values you are able to get a good speed up with the new version.</div><div><br></div><div>Example of use:</div><div>iteruniq(<list of set>, key=frozenset)</div>
<div><br></div><div>With really small non-hashable lists, the original is significantly better (3x).</div>