Skip to content

Instantly share code, notes, and snippets.

@pkofod
Created January 18, 2017 09:09
Show Gist options
  • Save pkofod/12b5587964b9a69a00bdc7130366d045 to your computer and use it in GitHub Desktop.
Save pkofod/12b5587964b9a69a00bdc7130366d045 to your computer and use it in GitHub Desktop.
using BenchmarkTools
K = 5
N = 3
z = [rand(20000, K) for i =1:N]
P = [rand(20000) for i = 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)
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
@benchmark test1(P, z)
@benchmark test2(P, z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment