[Numpy-svn] r4588 - trunk/benchmarks

numpy-svn at scipy.org numpy-svn at scipy.org
Sat Dec 15 15:35:27 EST 2007


Author: jarrod.millman
Date: 2007-12-15 14:35:18 -0600 (Sat, 15 Dec 2007)
New Revision: 4588

Modified:
   trunk/benchmarks/benchmark.py
   trunk/benchmarks/creating.py
   trunk/benchmarks/simpleindex.py
   trunk/benchmarks/sorting.py
Log:
updating to us import numpy as np convention


Modified: trunk/benchmarks/benchmark.py
===================================================================
--- trunk/benchmarks/benchmark.py	2007-12-15 19:53:29 UTC (rev 4587)
+++ trunk/benchmarks/benchmark.py	2007-12-15 20:35:18 UTC (rev 4588)
@@ -17,7 +17,7 @@
             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)
 

Modified: trunk/benchmarks/creating.py
===================================================================
--- trunk/benchmarks/creating.py	2007-12-15 19:53:29 UTC (rev 4587)
+++ trunk/benchmarks/creating.py	2007-12-15 20:35:18 UTC (rev 4588)
@@ -7,8 +7,8 @@
               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()

Modified: trunk/benchmarks/simpleindex.py
===================================================================
--- trunk/benchmarks/simpleindex.py	2007-12-15 19:53:29 UTC (rev 4587)
+++ trunk/benchmarks/simpleindex.py	2007-12-15 20:35:18 UTC (rev 4588)
@@ -5,21 +5,25 @@
 #   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 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)
+

Modified: trunk/benchmarks/sorting.py
===================================================================
--- trunk/benchmarks/sorting.py	2007-12-15 19:53:29 UTC (rev 4587)
+++ trunk/benchmarks/sorting.py	2007-12-15 20:35:18 UTC (rev 4588)
@@ -5,21 +5,21 @@
 
 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()




More information about the Numpy-svn mailing list