type StateT
x::Int64
y::Int64
end
immutable StateI
x::Int64
y::Int64
end
function test1(n::Int64)
for i=1:n, j=1:n
s = StateT(i,j)
end
end
function test2(n::Int64)
for i=1:n, j=1:n
s = StateI(i,j)
end
end
@time test1(10_000) # 0.801656 seconds (100.00 M allocations: 2.980 GB, 20.56% gc time)
@time test2(10_000) # 0.000003 seconds (4 allocations: 160 bytes)
function test1(n::Int64)
tot = 0
for i=1:n, j=1:n
s = StateT(i,j)
tot += (s.x+s.y)
end
return tot
end
function test2(n::Int64)
tot = 0
for i=1:n, j=1:n
s = StateI(i,j)
tot += (s.x+s.y)
end
return tot
end
@time test1(10_000) # 0.717841 seconds (100.00 M allocations: 2.980 GB, 22.74% gc time)
@time test2(10_000) # 0.000009 seconds (5 allocations: 176 bytes)