Hi again,
Thanks for all the suggestions.
I'm a bit ashamed I overlooked the part of the documentation about types.
I skimmed through the DataFrames documentation and I don't think there's a
way to access data via keys.
As far as the two other solutions are concerned, I compared their
performance on a very simple test case, here it is if it can be of any
interest :
n = 100000
# Method 1: Type
type parameters
p1::Float64
p2::Float64
p3::Float64
end
p_method_1 = parameters(3.6, 0.6, 600.0)
function f1(p)
for i = 1:n
p.p1 += 0.1
p.p2 += 0.1
p.p3 += 0.1
end
end
# Method 2: Dictionnary
p_method_2 = {"p1" => 3.6, "p2" => 0.6, "p3" => 600.0}
function f2(p)
for i = 1:n
p["p1"] += 0.1
p["p2"] += 0.1
p["p3"] += 0.1
end
end
println("Method 1")
println(p_method_1)
@time f1(p_method_1)
println(p_method_1)
println("Method 2")
println(p_method_2)
@time f2(p_method_2)
println(p_method_2)
Here are the results:
Method 1
parameters(3.6,0.6,600.0)
elapsed time: 0.020289272 seconds (6610188 bytes allocated)
parameters(10003.600000018861,10000.60000001885,10600.000000020964)
Method 2
{"p3"=>600.0,"p2"=>0.6,"p1"=>3.6}
elapsed time: 0.120914516 seconds (16193368 bytes allocated)
{"p3"=>10600.000000020964,"p2"=>10000.60000001885,"p1"=>10003.600000018861}
The first method is by far the most efficient.