Skip to content

Instantly share code, notes, and snippets.

@nschloe
Created April 30, 2021 17:43
Show Gist options
  • Save nschloe/33b3c93b9bc0768394ba9edee1fda2bc to your computer and use it in GitHub Desktop.
Save nschloe/33b3c93b9bc0768394ba9edee1fda2bc to your computer and use it in GitHub Desktop.
dot vs einsum for 1D
import numpy as np
import perfplot
def dot(xy):
x, y = xy
return np.dot(x, y)
def einsum(xy):
x, y = xy
return np.einsum("i...,i...->...", x, y)
b = perfplot.bench(
setup=lambda n: np.random.rand(2, n),
kernels=[dot, einsum],
n_range=[2 ** k for k in range(25)],
)
b.save("out.svg")
b.show()
@nschloe
Copy link
Author

nschloe commented Apr 30, 2021

out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment