~ubuntu-branches/ubuntu/wily/python-fftw/wily

« back to all changes in this revision

Viewing changes to test/test_fftw3_threads.py

  • Committer: Package Import Robot
  • Author(s): Jerome Kieffer
  • Date: 2011-12-11 14:44:24 UTC
  • Revision ID: package-import@ubuntu.com-20111211144424-n2fel2ww3dlajmuf
Tags: upstream-0.2.2
ImportĀ upstreamĀ versionĀ 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import sys
 
2
sys.path.append('../build/lib')
 
3
sys.path.append('../build/lib.linux-x86_64-2.6')
 
4
import unittest
 
5
import time
 
6
import fftw3f
 
7
import numpy as np
 
8
import fftw3f.lib
 
9
import fftw3f.planning
 
10
import os
 
11
 
 
12
MAX_THREADS = 10
 
13
 
 
14
class ProductTestCase(unittest.TestCase):
 
15
 
 
16
    def test3D(self):
 
17
        repeats = 10
 
18
        shape = (256, 256, 16)
 
19
        lib = fftw3f
 
20
        tarray = np.random.random(shape).astype('f')
 
21
        farray = np.random.random(shape).astype('F')
 
22
        l = []
 
23
        for nthreads in range(1,MAX_THREADS):
 
24
            fftplan = lib.Plan(tarray,farray,'forward', nthreads=nthreads)
 
25
            ifftplan = lib.Plan(farray,tarray,'backward', nthreads=nthreads)        
 
26
            ti = time.time()
 
27
            for i in xrange(repeats):
 
28
                fftplan()
 
29
                ifftplan()
 
30
            to = time.time()-ti
 
31
            print '#threads:%s timing:%.3f speedup:%.3f'\
 
32
                % (nthreads, to, l[0]/to if l else 1)
 
33
            l.append(to)
 
34
 
 
35
if __name__ == '__main__':
 
36
    unittest.main()