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

scipy-svn@scip... scipy-svn@scip...
Thu Jun 26 21:14:17 CDT 2008


Author: ilan
Date: 2008-06-26 21:14:16 -0500 (Thu, 26 Jun 2008)
New Revision: 4483

Added:
   trunk/scipy/sandbox/mkufunc/test_speed.py
Modified:
   trunk/scipy/sandbox/mkufunc/head.c
Log:
Added test for speed comparison

Modified: trunk/scipy/sandbox/mkufunc/head.c
===================================================================
--- trunk/scipy/sandbox/mkufunc/head.c	2008-06-26 18:49:38 UTC (rev 4482)
+++ trunk/scipy/sandbox/mkufunc/head.c	2008-06-27 02:14:16 UTC (rev 4483)
@@ -1,4 +1,6 @@
 
+#include <stdio.h>
+#include <stdlib.h>
 #include <math.h>
 
 /* ================================================== g_prerequisite.h === */
@@ -362,19 +364,19 @@
 
 /*** conversions ***/
 
-#define OP_CAST_FLOAT_TO_INT(x,r)    r = (long)(x)
-#define OP_CAST_FLOAT_TO_UINT(x,r)   r = (unsigned long)(x)
-#define OP_CAST_INT_TO_FLOAT(x,r)    r = (double)(x)
-#define OP_CAST_UINT_TO_FLOAT(x,r)   r = (double)(x)
-#define OP_CAST_LONGLONG_TO_FLOAT(x,r) r = (double)(x)
-#define OP_CAST_BOOL_TO_FLOAT(x,r)   r = (double)(x)
+#define OP_CAST_FLOAT_TO_INT(x,r)       r = (long)(x)
+#define OP_CAST_FLOAT_TO_UINT(x,r)      r = (unsigned long)(x)
+#define OP_CAST_INT_TO_FLOAT(x,r)       r = (double)(x)
+#define OP_CAST_UINT_TO_FLOAT(x,r)      r = (double)(x)
+#define OP_CAST_LONGLONG_TO_FLOAT(x,r)  r = (double)(x)
+#define OP_CAST_BOOL_TO_FLOAT(x,r)      r = (double)(x)
 
 #ifdef HAVE_LONG_LONG
-#define OP_CAST_FLOAT_TO_LONGLONG(x,r) r = (long long)(x)
+#define OP_CAST_FLOAT_TO_LONGLONG(x,r)  r = (long long)(x)
 #endif
 
+/* ================================================== support.h ========== */
 
+#define RPyField(ptr, name)             NULL
 
-
 /* ================================================== EOF ================ */
-/* ================================================== EOF ================ */

Added: trunk/scipy/sandbox/mkufunc/test_speed.py
===================================================================
--- trunk/scipy/sandbox/mkufunc/test_speed.py	2008-06-26 18:49:38 UTC (rev 4482)
+++ trunk/scipy/sandbox/mkufunc/test_speed.py	2008-06-27 02:14:16 UTC (rev 4483)
@@ -0,0 +1,37 @@
+#!/usr/bin/env python
+from math import sin, cos
+import time
+
+from numpy import arange, vectorize
+
+from mkufunc import mkufunc
+
+
+def f(x):
+    return 4.2 * x * x + 3.7 * x + 1.5
+
+
+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
+n_time = time.time() - start_time
+print 'numpy: %.6f sec' % n_time
+
+start_time = time.time()
+y = vfunc(x)
+v_time = time.time() - start_time
+print 'vectorize: %.6f sec' % v_time
+
+start_time = time.time()
+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 vectorize:", v_time/u_time


Property changes on: trunk/scipy/sandbox/mkufunc/test_speed.py
___________________________________________________________________
Name: svn:executable
   + *



More information about the Scipy-svn mailing list