~mogurijin/pyeigen/py3k

« back to all changes in this revision

Viewing changes to test/benchmark/matrixX.py

  • Committer: Jussi Lepistö
  • Date: 2010-04-07 07:24:37 UTC
  • Revision ID: jussi.lepisto@iki.fi-20100407072437-i8769yqa2hbf7rn9
- Enable vectorization (SSE2 instruction set)
- Add 1000x1000 matrix benchmark
- Change NumPy type from array to matrix in benchmarks

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import timeit
 
2
 
 
3
number = 10
 
4
repeat = 3
 
5
 
 
6
test_pyeigen = True
 
7
test_numpy = True
 
8
 
 
9
m1 = None
 
10
m2 = None
 
11
 
 
12
def test(stmt, setup):
 
13
    return timeit.repeat(stmt, setup, repeat=repeat, number=number)
 
14
 
 
15
def run_tests():
 
16
    global m1, m2
 
17
 
 
18
    # Pyeigen
 
19
    try:
 
20
        import pyeigen
 
21
    except ImportError:
 
22
        pyeigen = None
 
23
    
 
24
    if test_pyeigen and pyeigen is not None:
 
25
        print "PyEigen"
 
26
        m1 = pyeigen.MatrixXf.random(1000, 1000)
 
27
        m2 = pyeigen.MatrixXf.random(1000, 1000)
 
28
        setup = "from __main__ import m1, m2"
 
29
    
 
30
        print "Add:", test("m1 + m2", setup) 
 
31
        print "Matrix multiply:", test("m1 * m2", setup)
 
32
        print "Scalar multiply:", test("m1 * 2.0", setup)
 
33
        print
 
34
 
 
35
    # Numpy
 
36
    try:
 
37
        import numpy.matlib
 
38
    except ImportError:
 
39
        numpy = None
 
40
    
 
41
    if test_numpy and numpy is not None:
 
42
        print "NumPy"
 
43
        m1 = numpy.matlib.rand((1000, 1000)).astype(numpy.float32)
 
44
        m2 = numpy.matlib.rand((1000, 1000)).astype(numpy.float32)
 
45
        setup = "from __main__ import m1, m2"
 
46
    
 
47
        print "Add:", test("m1 + m2", setup)
 
48
        print "Matrix multiply:", test("m1 * m2", setup)
 
49
        print "Scalar multiply:", test("m1 * 2.0", setup)
 
50
        print
 
51
 
 
52
if __name__ == "__main__":
 
53
    run_tests()