Last active
November 29, 2015 00:07
-
-
Save sylvchev/87e42c8fe761a5279213 to your computer and use it in GitHub Desktop.
Benchmarking scipy and numpy, to be measured with MKL, OpenBLAS and Netlib.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import sys | |
from numpy import array | |
from numpy.random import rand | |
from timeit import Timer | |
import pickle | |
from os import system | |
if len(sys.argv) is not 2: | |
print ("usage: numpy_benchmark.py whichpython") | |
sys.exit(0) | |
else: | |
python_version = sys.argv[1] | |
s = 2000 | |
repetition = 20 | |
A, B = rand(s, s), rand(s, s) | |
t = Timer("A.dot(B)", "import numpy; from __main__ import A, B") | |
dp = array(t.repeat(repetition, 1)) | |
print ("dot product for ", s, "x", s, "matrices :", "%.2f+/-%.4f seconds" %(dp.mean(), dp.std())) | |
setup = "import numpy;\ | |
import scipy.linalg as linalg;\ | |
x = numpy.random.random((%d,%d));\ | |
z = numpy.dot(x, x.T)" % (s, s) | |
t = Timer("linalg.cholesky(z, lower=True)", setup=setup) | |
ch = array(t.repeat(repetition, 1)) | |
print ("cholesky decomposition for ", s, "x", s, "matrices :", "%.2f+/-%.4f seconds" %(ch.mean(), ch.std())) | |
t = Timer("linalg.svd(z)", setup=setup) | |
sv = array(t.repeat(repetition, 1)) | |
print ("SVD decomposition for ", s, "x", s, "matrices :", "%.2f+/-%.4f seconds" %(sv.mean(), sv.std())) | |
fn = "scipy_"+python_version+".pck" | |
with open(fn, 'w') as f: | |
o = {'dot':dp, 'chol':ch, 'svd':sv} | |
pickle.dump(o, f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment