In [1]:
import os
import numpy
import time

In [2]:
def elementwise_product(x, y):
assert(len(x) == len(y))
z = numpy.zeros(len(x))
for i in range(len(x)):
z[i] = x[i] * y[i]
return z

return x * y

In [9]:
n = 1024 * 1024 * 128
x = numpy.random.rand(n)
y = numpy.random.rand(n)

In [5]:
t = time.time()
elementwise_product(x, y)
elapsed = time.time() - t
print("time elapsed: %f" % elapsed)

time elapsed: 0.260288

In [11]:
t = time.time()
for i in range(10):
elapsed = time.time() - t
print("time elapsed: %f" % elapsed)

time elapsed: 6.335351

In [12]:
n = 1024 * 16
p = 32
A = numpy.random.rand(n, n)
X = numpy.random.rand(n, p)
X1 = numpy.random.rand(n, 1)

In [13]:
t = time.time()
for i in range(10):
numpy.dot(A, X)
elapsed_4t_mm = time.time() - t
print("time elapsed: %f" % elapsed_4t_mm)

time elapsed: 3.337421

In [14]:
t = time.time()
for i in range(10):
numpy.dot(A, X1)
elapsed_4t_mv = time.time() - t
print("time elapsed: %f" % elapsed_4t_mv)

time elapsed: 1.092257


## RESTART THE KERNEL¶

In [1]:
import os
import numpy
import time

In [2]:
n = 1024 * 16
p = 32
A = numpy.random.rand(n, n)
X = numpy.random.rand(n, p)
X1 = numpy.random.rand(n, 1)

In [3]:
t = time.time()
for i in range(10):
numpy.dot(A, X)
elapsed_1t_mm = time.time() - t
print("time elapsed: %f" % elapsed_1t_mm)

time elapsed: 6.409531

In [4]:
t = time.time()
for i in range(10):
numpy.dot(A, X1)
elapsed_1t_mv = time.time() - t
print("time elapsed: %f" % elapsed_1t_mv)

time elapsed: 1.237670

In [ ]:


In [ ]: