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

x = np.random.randn(1080, 30)

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 = 180

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

TIME_START_1 = time()
for i in range(100):
    for i_main, state in enumerate(train_loader):
        pass
print("START_1 - ", time() - TIME_START_1)


TIME_START_2 = time()
for i in range(100):
    for st in range(0, len(x), batch):
        state = x[st:st+batch]
print("START_2 - ", time() - TIME_START_2)

START_1 -  0.47510671615600586
START_2 -  0.0002009868621826172
How much faster is the loop than Dataloader…
Although maybe I’m doing something wrong…