summaryrefslogtreecommitdiff
path: root/doc/numpybook/comparison/timing.py
blob: 14841d7cbe8fbe5717f82452901d16f6a763e7b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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)