I'm wondering why a for-loop over samples of a tf.data.Dataset is so much slower than looping over the corresponding numpy array.
import numpy as np
import tensorflow as tf
import time
a = np.ones(100000, dtype=np.float32)
start_time = time.time()
for x in a:
pass
print(time.time() - start_time)
start_time = time.time()
for x in tf.data.Dataset.from_tensor_slices(a):
pass
print(time.time() - start_time)
0.05548405647277832
5.67711615562439
My TensorFlow version is 2.0.0.