[Scipy-svn] r4487 - trunk/scipy/sandbox/mkufunc

scipy-svn@scip... scipy-svn@scip...
Fri Jun 27 17:29:23 CDT 2008


Author: ilan
Date: 2008-06-27 17:29:20 -0500 (Fri, 27 Jun 2008)
New Revision: 4487

Modified:
   trunk/scipy/sandbox/mkufunc/test_speed.py
Log:
Added blitz

Modified: trunk/scipy/sandbox/mkufunc/test_speed.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/test_speed.py	2008-06-27 19:37:49 UTC (rev 4486)
+++ trunk/scipy/sandbox/mkufunc/test_speed.py	2008-06-27 22:29:20 UTC (rev 4487)
@@ -2,7 +2,8 @@
 from math import sin, cos
 import time
 
-from numpy import arange, vectorize
+from numpy import arange, vectorize, allclose
+from scipy import weave
 
 from mkufunc import mkufunc
 
@@ -11,27 +12,38 @@
     return 4.2 * x * x + 3.7 * x + 1.5
 
 
+vfunc = vectorize(f)
+
 ufunc = mkufunc([(float, float)])(f)
 
-vfunc = vectorize(f)
 
-
 x = arange(0, 1000, 0.001)    #print "x =", x, x.dtype
 
 start_time = time.time()
-y = 4.2 * x * x + 3.7 * x + 1.5
+b_y = x.copy()
+weave.blitz("b_y[:] = 4.2 * x[:] * x[:] + 3.7 * x[:] + 1.5")
+b_time = time.time() - start_time
+print 'blitz: %.6f sec' % b_time
+
+start_time = time.time()
+n_y = f(x)
 n_time = time.time() - start_time
 print 'numpy: %.6f sec' % n_time
 
 start_time = time.time()
-y = vfunc(x)
+v_y = vfunc(x)
 v_time = time.time() - start_time
 print 'vectorize: %.6f sec' % v_time
 
 start_time = time.time()
-y = ufunc(x)
+u_y = ufunc(x)
 u_time = time.time() - start_time
 print 'mkufunc: %.6f sec' % u_time
 
-print "speedup over numpy:", n_time/u_time
+print "speedup over blitz:",     b_time/u_time
+print "speedup over numpy:",     n_time/u_time
 print "speedup over vectorize:", v_time/u_time
+
+assert allclose(b_y, n_y)
+assert allclose(v_y, n_y)
+assert allclose(u_y, n_y)



More information about the Scipy-svn mailing list