summaryrefslogtreecommitdiff
path: root/benchmarks
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
parent02ee35a7e1c722a1cdac8f3a60fe9ef7aa079a37 (diff)
downloadnumpy-1c913bc6a7334e69bacf2bf1021ee6d03340a9fd.tar.gz
updating to us import numpy as np convention
Diffstat (limited to 'benchmarks')
-rw-r--r--benchmarks/benchmark.py2
-rw-r--r--benchmarks/creating.py6
-rw-r--r--benchmarks/simpleindex.py31
-rw-r--r--benchmarks/sorting.py18
4 files changed, 32 insertions, 25 deletions
diff --git a/benchmarks/benchmark.py b/benchmarks/benchmark.py
index 59e464686..526a69d58 100644
--- a/benchmarks/benchmark.py
+++ b/benchmarks/benchmark.py
@@ -17,7 +17,7 @@ class Benchmark(dict):
modules = [module]
for m in modules:
- setup_str = 'import %s; import %s as N; ' % (m,m) \
+ setup_str = 'import %s; import %s as np; ' % (m,m) \
+ setup_str
self.module_test[m] = Timer(test_str, setup_str)
diff --git a/benchmarks/creating.py b/benchmarks/creating.py
index 981c7fe47..6f8dc0217 100644
--- a/benchmarks/creating.py
+++ b/benchmarks/creating.py
@@ -7,8 +7,8 @@ b = Benchmark(modules,
title='Creating %s zeros.' % N,
runs=3,reps=10000)
-b['numpy'] = ('a=N.zeros(shape,type)', 'shape=%s;type=float' % N)
-b['Numeric'] = ('a=N.zeros(shape,type)', 'shape=%s;type=N.Float' % N)
-b['numarray'] = ('a=N.zeros(shape,type)', "shape=%s;type=N.Float" % N)
+b['numpy'] = ('a=np.zeros(shape,type)', 'shape=%s;type=float' % N)
+b['Numeric'] = ('a=np.zeros(shape,type)', 'shape=%s;type=np.Float' % N)
+b['numarray'] = ('a=np.zeros(shape,type)', "shape=%s;type=np.Float" % N)
b.run()
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)
+
diff --git a/benchmarks/sorting.py b/benchmarks/sorting.py
index 0148508cc..5a23506b5 100644
--- a/benchmarks/sorting.py
+++ b/benchmarks/sorting.py
@@ -5,21 +5,21 @@ b = Benchmark(modules,runs=3,reps=100)
N = 10000
b.title = 'Sorting %d elements' % N
-b['numarray'] = ('a=N.array(None,shape=%d,typecode="i");a.sort()'%N,'')
-b['numpy'] = ('a=N.empty(shape=%d, dtype="i");a.sort()'%N,'')
-b['Numeric'] = ('a=N.empty(shape=%d, typecode="i");N.sort(a)'%N,'')
+b['numarray'] = ('a=np.array(None,shape=%d,typecode="i");a.sort()'%N,'')
+b['numpy'] = ('a=np.empty(shape=%d, dtype="i");a.sort()'%N,'')
+b['Numeric'] = ('a=np.empty(shape=%d, typecode="i");np.sort(a)'%N,'')
b.run()
N1,N2 = 100,100
b.title = 'Sorting (%d,%d) elements, last axis' % (N1,N2)
-b['numarray'] = ('a=N.array(None,shape=(%d,%d),typecode="i");a.sort()'%(N1,N2),'')
-b['numpy'] = ('a=N.empty(shape=(%d,%d), dtype="i");a.sort()'%(N1,N2),'')
-b['Numeric'] = ('a=N.empty(shape=(%d,%d),typecode="i");N.sort(a)'%(N1,N2),'')
+b['numarray'] = ('a=np.array(None,shape=(%d,%d),typecode="i");a.sort()'%(N1,N2),'')
+b['numpy'] = ('a=np.empty(shape=(%d,%d), dtype="i");a.sort()'%(N1,N2),'')
+b['Numeric'] = ('a=np.empty(shape=(%d,%d),typecode="i");np.sort(a)'%(N1,N2),'')
b.run()
N1,N2 = 100,100
b.title = 'Sorting (%d,%d) elements, first axis' % (N1,N2)
-b['numarray'] = ('a=N.array(None,shape=(%d,%d), typecode="i");a.sort(0)'%(N1,N2),'')
-b['numpy'] = ('a=N.empty(shape=(%d,%d),dtype="i");N.sort(a,0)'%(N1,N2),'')
-b['Numeric'] = ('a=N.empty(shape=(%d,%d),typecode="i");N.sort(a,0)'%(N1,N2),'')
+b['numarray'] = ('a=np.array(None,shape=(%d,%d), typecode="i");a.sort(0)'%(N1,N2),'')
+b['numpy'] = ('a=np.empty(shape=(%d,%d),dtype="i");np.sort(a,0)'%(N1,N2),'')
+b['Numeric'] = ('a=np.empty(shape=(%d,%d),typecode="i");np.sort(a,0)'%(N1,N2),'')
b.run()