-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_tensorflow.py
More file actions
30 lines (24 loc) · 710 Bytes
/
Copy pathtest_tensorflow.py
File metadata and controls
30 lines (24 loc) · 710 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
import numpy as np
import time
import sys
NUM_THREADS = int(sys.argv[1])
N = 30000
print("Num threads", NUM_THREADS)
x_data = np.random.uniform(-1, 1, N)
y_data = np.random.uniform(-1, 1, N)
x = tf.placeholder("float64", name="x")
y = tf.placeholder("float64", name="y")
hit_tests = x ** 2 + y ** 2 < 1.0
hits = tf.reduce_sum(tf.cast(hit_tests, "int32"))
with tf.Session(
config=tf.ConfigProto(
inter_op_parallelism_threads=NUM_THREADS,
intra_op_parallelism_threads=NUM_THREADS,
)
) as sess:
start = time.time()
for i in range(10000):
sess.run(hits, {x: x_data, y: y_data})
print(time.time() - start)