The following code is what I used to test the performance:
import time
import numpy as np
import tensorflow as tf
t = time.time()
for i in range(400):
a = np.random.uniform(0,1,(1000,2000))
print("np.random.uniform: {} seconds".format(time.time() - t))
t = time.time()
for i in range(400):
a = np.random.random((1000,2000))
print("np.random.random: {} seconds".format(time.time() - t))
t = time.time()
for i in range(400):
a = tf.random_uniform((1000,2000),dtype=tf.float64);
print("tf.random_uniform: {} seconds".format(time.time() - t))
All the three segments generate a uniformly random 1000*2000 matrix in double precision 400 times. The timing differences are striking. On my Mac,
np.random.uniform: 10.4318959713 seconds
np.random.random: 8.76161003113 seconds
tf.random_uniform: 1.21312117577 seconds
Why is tensorflow much faster than numpy?
Aucun commentaire:
Enregistrer un commentaire