import numpy as np
from torch.utils.data import Dataset, DataLoader
from time import time
import torch

dataload2 = np.load('all_np_stock_2y30close.npz')
all_state = dataload2['arr_0']
all_state_torch = torch.from_numpy(all_state)
#print(len(all_state))

class NetDataset(Dataset):
    # Initialize your data, download, etc.
    def __init__(self, state): 
        self.state = state
    def __getitem__(self, index):
        return self.state[index]
    def __len__(self):
        return len(self.state)

batch = 1080

dataset = NetDataset(all_state)
train_loader = DataLoader(dataset=dataset, batch_size=batch, shuffle=False)

TIME_ALL_START = time()
for st in range(0, len(all_state), batch):
#for state in train_loader:
    state = all_state_torch[st:st+batch]
print("ALL_START - ", time() - TIME_ALL_START)

For a long time I could not understand why my program is slow. I used Dataloader. then I decided to test the operation on a simple loop. I took a step to get the batch. My program began to work 10 times faster. Who can explain to me why the dataloader is so slow? I did not upload data to my network, I just checked how Dataloader works on an empty loop.