Pass the arguments, please
16 Jan 2015
According to Julia documentation…
It is […] worth emphasizing that functions should take arguments, instead of operating directly on global variables (aside from constants like
pi
).
Let’s see if there is a difference in runtime depending on whether a function takes arguments, takes globals, or uses internal variables (the latter may not be a very fair comparison in this case).
Output:
devect_global elapsed time: 2.326460502 seconds (808,400,000 bytes allocated, 11.88% gc time)
devect_internal elapsed time: 0.110363588 seconds (86,281,768 bytes allocated, 28.07% gc time)
devect_arg elapsed time: 0.034368194 seconds (5,954,048 bytes allocated)
Clear difference not just in the runtime, but also in the memory use.