Skip to content

Instantly share code, notes, and snippets.

@mateuszbaran
Last active June 5, 2019 11:19
Show Gist options
  • Save mateuszbaran/9fa1c7ffcd3f9445c80503e80bd0dad8 to your computer and use it in GitHub Desktop.
Save mateuszbaran/9fa1c7ffcd3f9445c80503e80bd0dad8 to your computer and use it in GitHub Desktop.
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