-
-
Notifications
You must be signed in to change notification settings - Fork 213
/
Copy pathissue-36.py
37 lines (28 loc) · 898 Bytes
/
issue-36.py
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
31
32
33
34
35
36
37
# Small benchmark to get the even point where the threading code
# performs better than the serial code. See issue #36 for details.
from __future__ import print_function
from time import time
import numpy as np
from numpy.testing import assert_array_equal
import numexpr as ne
def bench(N):
print("*** array length:", N)
a = np.arange(N)
t0 = time()
ntimes = (1000*2**15) // N
for i in range(ntimes):
ne.evaluate('a>1000')
print("numexpr--> %.3g" % ((time()-t0)/ntimes,))
t0 = time()
for i in range(ntimes):
eval('a>1000')
print("numpy--> %.3g" % ((time()-t0)/ntimes,))
if __name__ == "__main__":
print("****** Testing with 1 thread...")
ne.set_num_threads(1)
for N in range(10, 20):
bench(2**N)
print("****** Testing with 2 threads...")
ne.set_num_threads(2)
for N in range(10, 20):
bench(2**N)