Last active
December 19, 2015 20:52
-
-
Save r9y9/d1341b9e8bfc3b141987 to your computer and use it in GitHub Desktop.
BLAS.axpy! と forループ愚直計算はどっちが速いのか実験
This file contains 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
function perf(a=1.0, N=1000; n=100) | |
srand(98765) | |
X = rand(N, N) | |
Y = rand(N, N) | |
println("N=$N") | |
print(" BLAS: ") | |
gc_enable(false) | |
gc() | |
@time for i in 1:n | |
BLAS.axpy!(a, X, Y) | |
end | |
print(" for: ") | |
gc() | |
@time begin | |
for j in 1:n | |
for i in eachindex(X) | |
@inbounds Y[i] = a*X[i] + Y[i] | |
end | |
end | |
end | |
gc_enable(true) | |
end | |
versioninfo() | |
for N in [100, 1000, 3000, 5000, 10000] | |
perf(5.0, N, n=1000) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
実行結果: