Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DanHickstein/9c3b3c002127be8e6619 to your computer and use it in GitHub Desktop.
Save DanHickstein/9c3b3c002127be8e6619 to your computer and use it in GitHub Desktop.
import numpy as np
import scipy
import time
import matplotlib.pyplot as plt
print np.__file__
ax = plt.subplot(111)
plt.ion()
plt.show()
ax.set_xscale('log')
ax.set_yscale('log')
ax.set_xlabel('N (size of NxN matrix)')
ax.set_ylabel('Time for dot product (sec)')
ax.set_title('Comparison of scipy to numpy')
sizes = []
nps = []
sps = []
for size in np.logspace(2.3,3.7,15):
x = np.random.random((size,size))
y = np.random.random((size,size))
sizes.append(size)
np_start = time.time()
np.dot(x,y)
np_time = time.time() - np_start
sp_start = time.time()
scipy.dot(x,y)
sp_time = time.time() - sp_start
nps.append(np_time)
sps.append(sp_time)
if 'line1' not in locals():
line1, = plt.plot(size, np_time, color='r', marker='o', ms=6, mec='none', label='numpy (Apple Accelerate)')
line2, = plt.plot(size, sp_time, color='b', marker='o', ms=6, mec='none', label='scipy (Fortran?)')
ax.legend(fontsize=10, frameon=False, loc=2)
else:
line1.set_data(sizes, nps)
line2.set_data(sizes, sps)
print '%ix%i - Numpy: %.1f ms, scipy: %.1f ms'%(size, size, np_time*1000, sp_time*1000)
ax.relim()
ax.autoscale_view(True,True,True)
plt.draw()
plt.ioff()
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment