This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Antony.Lee
Recipients Antony.Lee
Date 2020-04-17.20:58:29
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1587157109.99.0.0253750787201.issue40313@roundup.psfhosted.org>
In-reply-to
Content
Consider the following example, linewrapping 10^4 bytes in hex form to 128 characters per line, on Py 3.8.2 (Arch Linux repo package):

    In [1]: import numpy as np, math

    In [2]: data = np.random.randint(0, 256, (100, 100), dtype=np.uint8).tobytes()                  

    In [3]: %timeit data.hex("\n", -64)
    123 µs ± 5.8 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each)

    In [4]: %timeit h = data.hex(); "\n".join([h[n * 128 : (n+1) * 128] for n in range(math.ceil(len(h) / 128))])
    45.4 µs ± 746 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)

    In [5]: h = data.hex(); "\n".join([h[n * 128 : (n+1) * 128] for n in range(math.ceil(len(h) / 128))]) == data.hex("\n", -64)                                                                       
    Out[5]: True

(the last line checks the validity of the code.)

It appears that a naive manual wrap is nearly 3x faster than the builtin functionality.
History
Date User Action Args
2020-04-17 20:58:30Antony.Leesetrecipients: + Antony.Lee
2020-04-17 20:58:29Antony.Leesetmessageid: <1587157109.99.0.0253750787201.issue40313@roundup.psfhosted.org>
2020-04-17 20:58:29Antony.Leelinkissue40313 messages
2020-04-17 20:58:29Antony.Leecreate