nikcleju@7
|
1 """
|
nikcleju@7
|
2 Benchmark script to be used to evaluate the performance improvement of the MKL
|
nikcleju@7
|
3 """
|
nikcleju@7
|
4
|
nikcleju@7
|
5 import os
|
nikcleju@7
|
6 import sys
|
nikcleju@7
|
7 import timeit
|
nikcleju@7
|
8
|
nikcleju@7
|
9 import numpy
|
nikcleju@7
|
10 from numpy.random import random
|
nikcleju@7
|
11
|
nikcleju@7
|
12 def test_eigenvalue():
|
nikcleju@7
|
13 """
|
nikcleju@7
|
14 Test eigen value computation of a matrix
|
nikcleju@7
|
15 """
|
nikcleju@7
|
16 i = 500
|
nikcleju@7
|
17 data = random((i,i))
|
nikcleju@7
|
18 result = numpy.linalg.eig(data)
|
nikcleju@7
|
19
|
nikcleju@7
|
20 def test_svd():
|
nikcleju@7
|
21 """
|
nikcleju@7
|
22 Test single value decomposition of a matrix
|
nikcleju@7
|
23 """
|
nikcleju@7
|
24 i = 1000
|
nikcleju@7
|
25 data = random((i,i))
|
nikcleju@7
|
26 result = numpy.linalg.svd(data)
|
nikcleju@7
|
27 result = numpy.linalg.svd(data, full_matrices=False)
|
nikcleju@7
|
28
|
nikcleju@7
|
29 def test_inv():
|
nikcleju@7
|
30 """
|
nikcleju@7
|
31 Test matrix inversion
|
nikcleju@7
|
32 """
|
nikcleju@7
|
33 i = 1000
|
nikcleju@7
|
34 data = random((i,i))
|
nikcleju@7
|
35 result = numpy.linalg.inv(data)
|
nikcleju@7
|
36
|
nikcleju@7
|
37 def test_det():
|
nikcleju@7
|
38 """
|
nikcleju@7
|
39 Test the computation of the matrix determinant
|
nikcleju@7
|
40 """
|
nikcleju@7
|
41 i = 1000
|
nikcleju@7
|
42 data = random((i,i))
|
nikcleju@7
|
43 result = numpy.linalg.det(data)
|
nikcleju@7
|
44
|
nikcleju@7
|
45 def test_dot():
|
nikcleju@7
|
46 """
|
nikcleju@7
|
47 Test the dot product
|
nikcleju@7
|
48 """
|
nikcleju@7
|
49 i = 1000
|
nikcleju@7
|
50 a = random((i, i))
|
nikcleju@7
|
51 b = numpy.linalg.inv(a)
|
nikcleju@7
|
52 result = numpy.dot(a, b) - numpy.eye(i)
|
nikcleju@7
|
53
|
nikcleju@7
|
54 # Test to start. The dict is the value I had with the MKL using EPD 6.0 and without MKL using EPD 5.1
|
nikcleju@7
|
55 tests = {test_eigenvalue : (752., 3376.),
|
nikcleju@7
|
56 test_svd : (4608., 15990.),
|
nikcleju@7
|
57 test_inv : (418., 1457.),
|
nikcleju@7
|
58 test_det : (186.0, 400.),
|
nikcleju@7
|
59 test_dot : (666., 2444.) }
|
nikcleju@7
|
60
|
nikcleju@7
|
61 # Setting the following environment variable in the shell executing the script allows
|
nikcleju@7
|
62 # you limit the maximal number threads used for computation
|
nikcleju@7
|
63 THREADS_LIMIT_ENV = 'OMP_NUM_THREADS'
|
nikcleju@7
|
64
|
nikcleju@7
|
65 def start_benchmark():
|
nikcleju@7
|
66 print """Benchmark is made against EPD 6.0,NumPy 1.4 with MKL and EPD 5.1, NumPy 1.3 with ATLAS
|
nikcleju@7
|
67 on a Thinkpad T60 with Intel CoreDuo 2Ghz CPU on Windows Vista 32 bit
|
nikcleju@7
|
68 """
|
nikcleju@7
|
69 if os.environ.has_key(THREADS_LIMIT_ENV):
|
nikcleju@7
|
70 print "Maximum number of threads used for computation is : %s" % os.environ[THREADS_LIMIT_ENV]
|
nikcleju@7
|
71 print ("-" * 80)
|
nikcleju@7
|
72 print "Starting timing with numpy %s\nVersion: %s" % (numpy.__version__, sys.version)
|
nikcleju@7
|
73 print "%20s : %10s - %5s / %5s" % ("Function", "Timing [ms]", "MKL", "No MKL")
|
nikcleju@7
|
74 for fun, bench in tests.items():
|
nikcleju@7
|
75 t = timeit.Timer(stmt="%s()" % fun.__name__, setup="from __main__ import %s" % fun.__name__)
|
nikcleju@7
|
76 res = t.repeat(repeat=3, number=1)
|
nikcleju@7
|
77 timing = 1000.0 * sum(res)/len(res)
|
nikcleju@7
|
78 print "%20s : %7.1f ms - %3.2f / %3.2f" % (fun.__name__, timing, bench[0]/timing, bench[1]/timing)
|
nikcleju@7
|
79
|
nikcleju@7
|
80 if __name__ == '__main__':
|
nikcleju@7
|
81 start_benchmark()
|