nikcleju@7: """ nikcleju@7: Benchmark script to be used to evaluate the performance improvement of the MKL nikcleju@7: """ nikcleju@7: nikcleju@7: import os nikcleju@7: import sys nikcleju@7: import timeit nikcleju@7: nikcleju@7: import numpy nikcleju@7: from numpy.random import random nikcleju@7: nikcleju@7: def test_eigenvalue(): nikcleju@7: """ nikcleju@7: Test eigen value computation of a matrix nikcleju@7: """ nikcleju@7: i = 500 nikcleju@7: data = random((i,i)) nikcleju@7: result = numpy.linalg.eig(data) nikcleju@7: nikcleju@7: def test_svd(): nikcleju@7: """ nikcleju@7: Test single value decomposition of a matrix nikcleju@7: """ nikcleju@7: i = 1000 nikcleju@7: data = random((i,i)) nikcleju@7: result = numpy.linalg.svd(data) nikcleju@7: result = numpy.linalg.svd(data, full_matrices=False) nikcleju@7: nikcleju@7: def test_inv(): nikcleju@7: """ nikcleju@7: Test matrix inversion nikcleju@7: """ nikcleju@7: i = 1000 nikcleju@7: data = random((i,i)) nikcleju@7: result = numpy.linalg.inv(data) nikcleju@7: nikcleju@7: def test_det(): nikcleju@7: """ nikcleju@7: Test the computation of the matrix determinant nikcleju@7: """ nikcleju@7: i = 1000 nikcleju@7: data = random((i,i)) nikcleju@7: result = numpy.linalg.det(data) nikcleju@7: nikcleju@7: def test_dot(): nikcleju@7: """ nikcleju@7: Test the dot product nikcleju@7: """ nikcleju@7: i = 1000 nikcleju@7: a = random((i, i)) nikcleju@7: b = numpy.linalg.inv(a) nikcleju@7: result = numpy.dot(a, b) - numpy.eye(i) nikcleju@7: nikcleju@7: # 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: tests = {test_eigenvalue : (752., 3376.), nikcleju@7: test_svd : (4608., 15990.), nikcleju@7: test_inv : (418., 1457.), nikcleju@7: test_det : (186.0, 400.), nikcleju@7: test_dot : (666., 2444.) } nikcleju@7: nikcleju@7: # Setting the following environment variable in the shell executing the script allows nikcleju@7: # you limit the maximal number threads used for computation nikcleju@7: THREADS_LIMIT_ENV = 'OMP_NUM_THREADS' nikcleju@7: nikcleju@7: def start_benchmark(): nikcleju@7: print """Benchmark is made against EPD 6.0,NumPy 1.4 with MKL and EPD 5.1, NumPy 1.3 with ATLAS nikcleju@7: on a Thinkpad T60 with Intel CoreDuo 2Ghz CPU on Windows Vista 32 bit nikcleju@7: """ nikcleju@7: if os.environ.has_key(THREADS_LIMIT_ENV): nikcleju@7: print "Maximum number of threads used for computation is : %s" % os.environ[THREADS_LIMIT_ENV] nikcleju@7: print ("-" * 80) nikcleju@7: print "Starting timing with numpy %s\nVersion: %s" % (numpy.__version__, sys.version) nikcleju@7: print "%20s : %10s - %5s / %5s" % ("Function", "Timing [ms]", "MKL", "No MKL") nikcleju@7: for fun, bench in tests.items(): nikcleju@7: t = timeit.Timer(stmt="%s()" % fun.__name__, setup="from __main__ import %s" % fun.__name__) nikcleju@7: res = t.repeat(repeat=3, number=1) nikcleju@7: timing = 1000.0 * sum(res)/len(res) nikcleju@7: print "%20s : %7.1f ms - %3.2f / %3.2f" % (fun.__name__, timing, bench[0]/timing, bench[1]/timing) nikcleju@7: nikcleju@7: if __name__ == '__main__': nikcleju@7: start_benchmark()