Skip to content

Commit 3fdd303

Browse files
author
Jonathan Rocher
committed
Separate benchmarch stuff into its own file.
1 parent 4f4af6d commit 3fdd303

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

numexpr/compare_numexpr_np.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
""" Comparing execution time between Numexpr and Numpy
2+
"""
3+
4+
import numpy as np
5+
from numexpr import evaluate
6+
import time
7+
from matplotlib.pyplot import (figure, plot, show, legend, xlabel, ylabel,
8+
yscale, title)
9+
10+
exec_times_np = []
11+
exec_times_ne = []
12+
13+
sizes = np.arange(0, 8, 0.5)
14+
for N in sizes:
15+
a = np.arange(10**N)
16+
b = np.arange(10**N)
17+
start1 = time.time()
18+
c1 = 2*a**3+b**2+16
19+
start2 = time.time()
20+
exec_times_np.append(start2-start1)
21+
print "Numpy polynomial computation %s seconds" % (start2-start1)
22+
start3 = time.time()
23+
c2 = evaluate("2*a**3+b**2+16")
24+
t4 = time.time()
25+
print "Using numexpr, the polynomial computation took %s seconds" % (t4-start3)
26+
exec_times_ne.append(t4-start3)
27+
del a
28+
del b
29+
del c1
30+
del c2
31+
32+
figure()
33+
plot(sizes, exec_times_np, label = "Numpy")
34+
plot(sizes, exec_times_ne, label = "Numexpr")
35+
xlabel("log10(size(arrays))")
36+
ylabel("execution time in sec")
37+
yscale("log")
38+
title("Comparing execution time to compute 2*a**3+b**2+16")
39+
legend(loc="upper left")
40+
show()
41+

0 commit comments

Comments
 (0)