I used the elements shift code from here. It works good. The piece of code I have used is as follows:
# https://stackoverflow.com/a/62841583/4272651
@nb.njit
def shift(arr, num, fill_value=False):
result = np.empty_like(arr)
if num > 0:
result[:num] = fill_value
result[num:] = arr[:-num]
elif num < 0:
result[num:] = fill_value
result[:num] = arr[-num:]
else:
result[:] = arr
return result
So I use it to do some bit operations and get what I want. Everything works great.
Here is the execution time vs the array size plot
The graphs are shifted by a certain x so that it is easier to see the overlap.
So as you see shifting takes a lot of time when starting up, but then decreases and increases steadily as the array length increases.
What is the reason behind that initial spike?