Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# !/usr/bin/env python
import sys
import numpy as np
import numpy.random as npr
from numpy.distutils.system_info import get_info
import time
if __name__ == '__main__':
# Run diagnostics
print("NumPy Version: %s" % np.__version__)
print("Max int: %i\n" % sys.maxsize)
info = get_info('blas_opt')
print('BLAS info:')
for kk, vv in info.items():
print(' * ' + kk + ' ' + str(vv))
print("\n")
# Run Test 1
N = 1
n = 1000
A = npr.randn(n, n)
B = npr.randn(n, n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("Dot product of two (%d,%d) matrices took %0.1f ms" % (n, n, 1e3 * td / N))
# Run Test 2
N = 100
n = 2000
A = npr.randn(n)
B = npr.randn(n)
t = time.time()
for i in range(N):
C = np.dot(A, B)
td = time.time() - t
print("Dot product of two (%d) d vectors took %0.2f us" % (n, 1e6 * td / N))
# Run Test 3
m, n = (1000, 2000)
A = npr.randn(m, n)
t = time.time()
[U, s, V] = np.linalg.svd(A, full_matrices=False)
td = time.time() - t
print("SVD of (%d,%d) matrix took %0.3f s" % (m, n, td))
# Run Test 4
n = 1000
A = npr.randn(n, n)
t = time.time()
w, v = np.linalg.eig(A)
td = time.time() - t
print("Eigen decomposion of (%d,%d) matrix took %0.3f s" % (n, n, td))
print("\n")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.