Understanding the performance of numpy memmap

I am trying to better understand how numpy memmap handles representations of very large files. After this script, an array with a mapping of 2048 ^ 3 with memory is opened and its thumbnail of 128 ^ 3 size is copied

import numpy as np
from time import time

FILE = '/Volumes/BlackBox/test.dat'
array = np.memmap(FILE, mode='r', shape=(2048,2048,2048), dtype=np.float64)

t = time()
for i in range(5):
    view = np.array(array[::16, ::16, ::16])
t = ((time() - t) / 5) * 1000
print "Time (ms): %i" % t

Usually it prints Time (ms): 80or so. However, if I change the purpose of the view to

view = np.array(array[1::16, 2::16, 3::16])

and run it three times, I get the following:

Time (ms): 9988
Time (ms): 79
Time (ms): 78

Does anyone understand why the first call is so slow?

+5
source share
1 answer

- ( ) , . , , . -, , , , ...

+3

All Articles