Last active
May 14, 2021 14:03
-
-
Save nschloe/0173fbcc6c59d2bc0fd4b439f820cfb7 to your computer and use it in GitHub Desktop.
Python x+a*y vs daxpy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
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