summaryrefslogtreecommitdiff
path: root/numpy/doc/numpybook/comparison/timing.py
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/doc/numpybook/comparison/timing.py')
-rw-r--r--numpy/doc/numpybook/comparison/timing.py63
1 files changed, 63 insertions, 0 deletions
diff --git a/numpy/doc/numpybook/comparison/timing.py b/numpy/doc/numpybook/comparison/timing.py
new file mode 100644
index 000000000..14841d7cb
--- /dev/null
+++ b/numpy/doc/numpybook/comparison/timing.py
@@ -0,0 +1,63 @@
+
+import timeit
+
+pyrex_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+pyrex_run = """
+b = filter.filter(a)
+"""
+
+weave_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+weave_run = """
+b = filter.filter(a)
+"""
+
+ctypes_pre = """
+import numpy as N
+a = N.random.rand(%d,%d)
+import filter
+"""
+
+ctypes_run = """
+b = filter.filter(a)
+"""
+
+f2py_pre = """
+import numpy as N
+a = N.random.rand(%d, %d).T
+import filter
+"""
+
+f2py_run = """
+b = N.zeros_like(a)
+filter.DFILTER2D(a,b)
+"""
+
+N = [10,20,30,40,50,100,200,300, 400, 500]
+
+res = {}
+
+import os
+import sys
+path = sys.path
+
+for kind in ['f2py']:#['ctypes', 'pyrex', 'weave', 'f2py']:
+ res[kind] = []
+ sys.path = ['/Users/oliphant/numpybook/%s' % (kind,)] + path
+ print sys.path
+ for n in N:
+ print "%s - %d" % (kind, n)
+ t = timeit.Timer(eval('%s_run'%kind), eval('%s_pre %% (%d,%d)'%(kind,n,n)))
+ mytime = min(t.repeat(3,100))
+ res[kind].append(mytime)
+
+