3 KiB
3 KiB
In [1]:
import numpy as np
In [2]:
def get_slice_and_perform_something(x, axis):
idx = 75
if axis == 0:
slice_ = x[idx, :]
else:
slice_ = x[:, idx]
# Here I divide by two but any other operation will do,
# we just want to simulate the fact that we actually need to read the memory
return slice_ // 2
In [3]:
page_size = 4096
n = 100
x = np.empty((page_size * n, page_size * n), dtype='int8')
In [4]:
x.shape
Out[4]:
In [5]:
%timeit get_slice_and_perform_something(x, axis=0)
In [6]:
%timeit get_slice_and_perform_something(x, axis=1)
In [10]:
886000 / 27.5
Out[10]:
In [ ]: