Created
January 18, 2017 09:01
-
-
Save pkofod/2983da0b3e19689f199d28d9acfc9835 to your computer and use it in GitHub Desktop.
fastslow
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
K = 5 | |
N = 3 | |
z = [rand(20000, K) for i =1:N] | |
P = [rand(20000) for i = 1:N] | |
Pm = rand(20000, N) | |
Pv = [@view Pm[:, j] for j = 1:N] | |
cache = zeros(20000, K) | |
function test1(P, z) | |
for i in eachindex(P) | |
cache .= P[i].*z[i] | |
end | |
end | |
function test2(P, z) | |
for i = 1:size(P, 2) | |
cache .= P[:, i].*z[i] | |
end | |
end | |
function test3(P, z) | |
J, I, K = length(P), size(z[1])... | |
for j = 1:J | |
for k = 1:K | |
for i = 1:I | |
cache[i, k] = P[j][i]*z[j][i,k] | |
end | |
end | |
end | |
end | |
function test4(P, z) | |
J, I, K = length(P), size(z[1])... | |
for j = 1:J | |
_P = P[j] | |
_z = z[j] | |
for k = 1:K | |
for i = 1:I | |
cache[i, k] = _P[i]*_z[i,k] | |
end | |
end | |
end | |
end | |
@benchmark test1(P, z) | |
@benchmark test1(Pv, z) | |
@benchmark test2(Pm, z) | |
@benchmark test3(P, z) | |
@benchmark test4(P, z) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment