title: Why Pytorch is slower than Tensorflow in read data
body: <p>I tried two version code for iterate MNIST data to compare the elapsed time.</p>
  <p><strong>Pytorch version</strong></p>
  <pre><code>import os
  os.environ[&quot;CUDA_VISIBLE_DEVICES&quot;] = &quot;0&quot;
  import torch
  from torchvision import datasets, transforms
  import matplotlib.pyplot as plt
  import time
  train_loader = torch.utils.data.DataLoader(
      datasets.MNIST('~/data', train=True, download=True,
                     transform=transforms.Compose([
                         transforms.ToTensor(),
                         # transforms.Normalize((0.1307,), (0.3081,))
                     ])),
      batch_size=30000, shuffle=True,pin_memory=True,num_workers=4)
  tic = time.time()
  for epoch in range(0, 5):
      for batch_idx, (data, target) in enumerate(train_loader):
          continue
  toc=time.time()
  print('elapsed time:',toc-tic)
  </code></pre>
  <p><strong>Tensorflow 2.x version</strong></p>
  <pre><code>import os
  os.environ['TF_CPP_MIN_LOG_LEVEL'] = '3'
  os.environ[&quot;CUDA_VISIBLE_DEVICES&quot;] = &quot;0&quot;
  import tensorflow as tf
  from tensorflow.keras import datasets
  import time
  (xs, ys), (xs_, ys_) = datasets.mnist.load_data()
  # print('datasets:', xs.shape, ys.shape, xs.min(), xs.max())
  xs = tf.convert_to_tensor(xs, dtype=tf.float32) / 255.
  db = tf.data.Dataset.from_tensor_slices((xs, ys))
  db = db.batch(30000)
  tic = time.time()
  for epoch in range(5):
      for step, (x, y) in enumerate(db):
          continue
  toc = time.time()
  print('elapsed time:', toc - tic)
  </code></pre>
  <p>And the result are TF elapsed 2s and Pytorch elapsed 15s.
  So, why Pytorch is slower than Tensorflow in read data?
  Am I setting it wrong?
  Thanks!</p>