Skip to content

Instantly share code, notes, and snippets.

@yukoba
Created June 19, 2016 01:44
Show Gist options
  • Save yukoba/719acfc489018b189840a0b1d9904d83 to your computer and use it in GitHub Desktop.
Save yukoba/719acfc489018b189840a0b1d9904d83 to your computer and use it in GitHub Desktop.
AutoGrad benchmark of matmul
import timeit
import autograd.numpy as np
from autograd import grad
def fn(a, b):
return np.sum(a @ b)
n = 1000
a = np.random.rand(n, n)
b = np.random.rand(n, n)
grad_fn = grad(fn)
t = min(timeit.repeat('grad_fn(a, b)', globals=globals(), number=1, repeat=10))
print("grad_fn(a, b) is %d ms" % (t * 1000))
t = min(timeit.repeat('fn(a, b)', globals=globals(), number=1, repeat=10))
print("fn(a, b) is %d ms" % (t * 1000))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment