summaryrefslogtreecommitdiff
path: root/benchmarks/simpleindex.py
diff options
context:
space:
mode:
authorJarrod Millman <millman@berkeley.edu>2007-12-15 20:35:18 +0000
committerJarrod Millman <millman@berkeley.edu>2007-12-15 20:35:18 +0000
commit1c913bc6a7334e69bacf2bf1021ee6d03340a9fd (patch)
treed34818de85d8a17da8fa209555eb9b643ef8d00c /benchmarks/simpleindex.py
parent02ee35a7e1c722a1cdac8f3a60fe9ef7aa079a37 (diff)
downloadnumpy-1c913bc6a7334e69bacf2bf1021ee6d03340a9fd.tar.gz
updating to us import numpy as np convention
Diffstat (limited to 'benchmarks/simpleindex.py')
-rw-r--r--benchmarks/simpleindex.py31
1 files changed, 19 insertions, 12 deletions
diff --git a/benchmarks/simpleindex.py b/benchmarks/simpleindex.py
index 459861b05..1575daf34 100644
--- a/benchmarks/simpleindex.py
+++ b/benchmarks/simpleindex.py
@@ -5,21 +5,25 @@ import timeit
# in the first place.
N = 30
+
code2 = r"""
for k in xrange(%d):
for l in xrange(%d):
res = a[k,l].item() + a[l,k].item()
""" % (N,N)
+
code3 = r"""
for k in xrange(%d):
for l in xrange(%d):
res = a[k][l] + a[l][k]
""" % (N,N)
+
code = r"""
for k in xrange(%d):
for l in xrange(%d):
res = a[k,l] + a[l,k]
""" % (N,N)
+
setup3 = r"""
import random
a = [[None for k in xrange(%d)] for l in xrange(%d)]
@@ -27,16 +31,19 @@ for k in xrange(%d):
for l in xrange(%d):
a[k][l] = random.random()
""" % (N,N,N,N)
-t1 = timeit.Timer(code, 'import numpy as N; a = N.random.rand(%d,%d)' % (N,N))
-t2 = timeit.Timer(code, 'import MLab as N; a=N.rand(%d,%d)' % (N,N))
-t3 = timeit.Timer(code, 'import numarray.mlab as N; a=N.rand(%d,%d)' % (N,N))
-t4 = timeit.Timer(code2, 'import numpy as N; a = N.random.rand(%d,%d)' % (N,N))
-t5 = timeit.Timer(code3, setup3)
-t6 = timeit.Timer("res = a + a.transpose()","import numpy as N; a=N.random.rand(%d,%d)" % (N,N))
+
+numpy_timer1 = timeit.Timer(code, 'import numpy as np; a = np.random.rand(%d,%d)' % (N,N))
+numeric_timer = timeit.Timer(code, 'import MLab as np; a=np.rand(%d,%d)' % (N,N))
+numarray_timer = timeit.Timer(code, 'import numarray.mlab as np; a=np.rand(%d,%d)' % (N,N))
+numpy_timer2 = timeit.Timer(code2, 'import numpy as np; a = np.random.rand(%d,%d)' % (N,N))
+python_timer = timeit.Timer(code3, setup3)
+numpy_timer3 = timeit.Timer("res = a + a.transpose()","import numpy as np; a=np.random.rand(%d,%d)" % (N,N))
+
print "shape = ", (N,N)
-print "NumPy 1: ", t1.repeat(3,100)
-print "NumPy 2: ", t4.repeat(3,100)
-print "Numeric: ", t2.repeat(3,100)
-print "Numarray: ", t3.repeat(3,100)
-print "Python: ", t5.repeat(3,100)
-print "Optimized: ", t6.repeat(3,100)
+print "NumPy 1: ", numpy_timer1.repeat(3,100)
+print "NumPy 2: ", numpy_timer2.repeat(3,100)
+print "Numeric: ", numeric_timer.repeat(3,100)
+print "Numarray: ", numarray_timer.repeat(3,100)
+print "Python: ", python_timer.repeat(3,100)
+print "Optimized: ", numpy_timer3.repeat(3,100)
+