thanks @eqy
I want to save all the time from disk read to decoder to image preprocessing, so to cache the dataloader’s final result (after preprocessing).  It is for validation, so shuffle=false doesn’t matter.
I have some other findings.


there’s no data copy here, I verified it with data_ptr().


the cached.append time is very small, but it adds much in the total time, don’t know why.


start = time.time()
cache_time = 0
cached = [] #queue.Queue()
for i, (_input, _target) in enumerate(val_loader):
    cache_start = time.time()
    cached.append((_input, _target))
    cache_time += (time.time() - cache_start) * 1000

total_time = time.time() - start

print(cache_time)
print(total_time)

For dataset with 50000 images, the cache_time is ~0.3ms, but the total time increases from 15 seconds to 22 seconds after I add ‘cached.append((_input, _target))’ in the code.

If I change pin_memory from true to false, all the time are expected, the cache_time is still ~0.3ms, and the total time is still around 15 seconds.

I see the time from 15s to 22s is not a big problem, but still want to understand why? thanks.