REVISION
Thanks to Chris Rakaukas for pointing out the error in my previous answer. I will leave this below as an illustration of what is not working. But Chris is right, the const declaration doesn’t actually improve performance when feeding a dictionary into a function. So see Chris's answer for the best solution to this problem:
D1 = [i => sind(i) for i = 0.0:5:3600]; const D2 = [i => sind(i) for i = 0.0:5:3600]; function test(D) for jdx = 1:1000
Old answer
If you want your dictionary to be constant, you can use:
const MyDict = getparameters( .. )
Refresh . Remember that in the Julia database, unlike some other languages, this does not mean that you cannot redefine constants, instead you just get a warning at the same time.
julia> const a = 2 2 julia> a = 3 WARNING: redefining constant a 3 julia> a 3
It is odd that you do not receive a warning about constant overriding when adding a new key-shaft pair to the dictionary. But you still see performance improvements from declaring it as constants:
D1 = [i => sind(i) for i = 0.0:5:3600]; const D2 = [i => sind(i) for i = 0.0:5:3600]; function test1() for jdx = 1:1000 for idx = 0.0:5:3600 a = D1[idx] end end end function test2() for jdx = 1:1000 for idx = 0.0:5:3600 a = D2[idx] end end end
Michael ohlrogge
source share