Last active
June 5, 2019 11:19
-
-
Save mateuszbaran/9fa1c7ffcd3f9445c80503e80bd0dad8 to your computer and use it in GitHub Desktop.
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
using LinearAlgebra | |
using BenchmarkTools | |
using StaticArrays | |
using UnsafeArrays | |
function rv(ar, n) | |
total = 0.0 | |
for i in 1:n | |
a = reshape(view(ar, (i-1)*4+1:i*4), (2,2)) | |
total += dot(a, a) | |
end | |
return total | |
end | |
function rvu(ar, n) | |
total = 0.0 | |
for i in 1:n | |
a = reshape(uview(ar, (i-1)*4+1:i*4), (2,2)) | |
total += dot(a, a) | |
end | |
return total | |
end | |
function rvs(ar, n) | |
total = 0.0 | |
for i in 1:n | |
a = reshape(uview(ar, (i-1)*4+1:i*4), Size(2,2)) | |
total += dot(a, a) | |
end | |
return total | |
end | |
function sa(ar) | |
total = 0.0 | |
for i in 1:length(ar) | |
total += dot(ar[i], ar[i]) | |
end | |
return total | |
end | |
A = collect(1.0:40.0) | |
A2 = [(@SMatrix Float64[i i+1; i+2 i+3]) for i in 1:4:40] | |
@btime rv($A, 10) | |
@btime rvu($A, 10) | |
@btime rvs($A, 10) | |
@btime sa($A2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment