summaryrefslogtreecommitdiff
path: root/benchmarks
diff options
context:
space:
mode:
authorTravis Oliphant <oliphant@enthought.com>2006-06-28 19:12:46 +0000
committerTravis Oliphant <oliphant@enthought.com>2006-06-28 19:12:46 +0000
commitb173aa1a6dc1c361d65150c6782db7618a5ff126 (patch)
treea8c930b14c52f3ddd7b8a30c6a470e193c1f1273 /benchmarks
parent05bb6ebdf72a580c16b20a2c6b29c1a1f6c254f1 (diff)
downloadpython-numpy-b173aa1a6dc1c361d65150c6782db7618a5ff126.tar.gz
python-numpy-b173aa1a6dc1c361d65150c6782db7618a5ff126.tar.bz2
python-numpy-b173aa1a6dc1c361d65150c6782db7618a5ff126.zip
Add simple indexing test.
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/simpleindex.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/benchmarks/simpleindex.py b/benchmarks/simpleindex.py
new file mode 100644
index 000000000..07c57f506
--- /dev/null
+++ b/benchmarks/simpleindex.py
@@ -0,0 +1,42 @@
+import timeit
+# This is to show that NumPy is a poorer choice than nested Python lists
+# if you are writing nested for loops.
+# This is slower than Numeric was but Numeric was slower than Python lists were
+# 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)]
+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.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.rand(%d,%d)' % (N,N))
+t5 = timeit.Timer(code3, setup3)
+t6 = timeit.Timer("res = a + a.transpose()","import numpy as N; a=N.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)