Skip to content

Instantly share code, notes, and snippets.

@nschloe
Last active May 14, 2021 14:03
Show Gist options
  • Save nschloe/0173fbcc6c59d2bc0fd4b439f820cfb7 to your computer and use it in GitHub Desktop.
Save nschloe/0173fbcc6c59d2bc0fd4b439f820cfb7 to your computer and use it in GitHub Desktop.
Python x+a*y vs daxpy
import numpy as np
import perfplot
from scipy.linalg.blas import daxpy
a = 1.3
def np_axpy(data):
x, y = data
return a * x + y
def sp_daxpy(data):
x, y = data
return daxpy(x, y, a=a)
b = perfplot.bench(
setup=lambda n: np.random.rand(2, n),
kernels=[np_axpy, sp_daxpy],
n_range=[2 ** k for k in range(24)],
)
b.save("out.png")
b.show()
@nschloe
Copy link
Author

nschloe commented May 14, 2021

out

@nschloe
Copy link
Author

nschloe commented May 14, 2021

See https://stackoverflow.com/a/67358748/353337 for a more comprehensive comparison.

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