Created
February 9, 2017 08:56
-
-
Save PatWie/7bd193c07ff72110997649cc83057699 to your computer and use it in GitHub Desktop.
compare staging vs FIFO
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.python.ops import data_flow_ops | |
import time | |
from contextlib import contextmanager | |
@contextmanager | |
def benchmark(name="unnamed context"): | |
elapsed = time.time() | |
yield | |
elapsed = time.time() - elapsed | |
print('[{}] finished in {} ms'.format(name, int(elapsed * 1000))) | |
tf.reset_default_graph() | |
with tf.Session() as sess: | |
dummy = tf.Variable(tf.random_normal([225, 225, 3], dtype=tf.float32, stddev=1e-1)) | |
sess.run(tf.global_variables_initializer()) | |
stager = data_flow_ops.StagingArea([tf.float32]) | |
enqeue_op = stager.put([dummy]) | |
dequeue_op = tf.reduce_sum(stager.get()) | |
for i in range(1000): | |
sess.run(enqeue_op) | |
with benchmark("staging"): | |
s = 0 | |
for i in range(1000): | |
s += sess.run(dequeue_op) | |
tf.reset_default_graph() | |
with tf.Session() as sess: | |
dummy = tf.Variable(tf.random_normal([225, 225, 3], dtype=tf.float32, stddev=1e-1)) | |
sess.run(tf.global_variables_initializer()) | |
stager = tf.FIFOQueue(1000, [tf.float32]) | |
enqeue_op = stager.enqueue([dummy]) | |
dequeue_op = tf.reduce_sum(stager.dequeue()) | |
for i in range(1000): | |
sess.run(enqeue_op) | |
with benchmark("FIFO"): | |
s = 0 | |
for i in range(1000): | |
s += sess.run(dequeue_op) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For those who may find this -- I got the following result. TensorFlow 1.10, Ubuntu, Using a TITAN Xp GPU.