• Kirill Smelkov's avatar
    lib/mem: Allow memcpy & friends to work on arbitrary-length buffer · a35106c2
    Kirill Smelkov authored
    - not only multiple of 8. We can do it by using uint8 typed arrays, and
    it does not hurt performance:
    
    In [1]: from wendelin.lib.mem import bzero, memset, memcpy
    In [2]: A = bytearray(2*1024*1024)
    In [3]: B = bytearray(2*1024*1024)
    
            memcpy(B, A)    bzero(A)        memset(A, 0xff)
    
    old:    718 µs          227 µs / 1116   228 µs / 1055 (*)
    new:    718 µs          176 µs / 1080   175 µs / 1048
    
        (*) the second number comes from e.g.
    
            In [8]: timeit bzero(A)
            The slowest run took 4.63 times longer than the fastest.
            This could mean that an intermediate result is being cached
            10000 loops, best of 3: 228 µs per loop
    
            so the second number is more realistic and says performance
            stays aproximately the same and only slightly improves.
    a35106c2
mem.py 1.37 KB