Message407059
> If there are enough use cases for it.
Well, that's the question. :-) *I* can't think of any good use cases, but maybe others can. But if we can't come up with some use cases, then this feels like a solution looking for a problem, and that makes it hard to justify both the short-term effort and the longer-term maintenance costs of adding the complexity.
FWIW, given a need to efficiently compute frequency tables for reasonably long byte data, I'd probably reach first for NumPy (and numpy.bincount in particular):
Python 3.10.0 (default, Nov 12 2021, 12:32:57) [Clang 12.0.5 (clang-1205.0.22.11)]
Type 'copyright', 'credits' or 'license' for more information
IPython 7.28.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import collections, numpy as np
In [2]: t = b'MDIAIHHPWIRRPFFPFHSPSRLFDQFFGEHLLESDLFSTATSLSPFYLRPPSFLRAPSWIDTGLSEMRLEKDRFSVNLDVKHFSPEELKVKVLGDVIEVHGKHEERQDEHGFISREFHRKYRI
...: PADVDPLAITSSLSSDGVLTVNGPRKQVSGPERTIPITREEKPAVAAAPKK'; t *= 100
In [3]: %timeit np.bincount(np.frombuffer(t, np.uint8))
32.7 µs ± 3.15 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [4]: %timeit collections.Counter(t)
702 µs ± 25.8 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
In [5]: %timeit sorted(t)
896 µs ± 64.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
|
Date |
User |
Action |
Args |
2021-11-26 15:50:23 | mark.dickinson | set | recipients:
+ mark.dickinson, tim.peters, brett.cannon, rhettinger, vstinner, Mark.Shannon, serhiy.storchaka, yselivanov, rhpvorderman |
2021-11-26 15:50:23 | mark.dickinson | set | messageid: <1637941823.13.0.15887204366.issue45902@roundup.psfhosted.org> |
2021-11-26 15:50:23 | mark.dickinson | link | issue45902 messages |
2021-11-26 15:50:22 | mark.dickinson | create | |
|