We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
We currently make use of global variables to avoid recomputing some solutions: see e.g. here:
function crowdingsolution() isdefined(@__MODULE__, :_solution_crowding) && return _solution_crowding global _solution_crowding = solve(crowding(), (1900, 2300)) return _solution_crowding end
After discussing the problem in the Discourse, we might consider using a closure as a more elegant approach:
let isfirstcall = true, output = 0 global function crowdingsolution() isfirstcall || return output isfirstcall = false return output = solve(crowding(), (1900, 2300)) end end
The text was updated successfully, but these errors were encountered:
I did a test out of curiosity and it seems that the closure is faster:
julia> function f_global() isdefined(@__MODULE__, :_output) && return _output global _output = 42 return _output end f_global (generic function with 1 method) julia> f_global() 42 julia> @benchmark f_global() BenchmarkTools.Trial: 10000 samples with 999 evaluations. Range (min … max): 12.185 ns … 54.210 ns ┊ GC (min … max): 0.00% … 0.00% Time (median): 13.612 ns ┊ GC (median): 0.00% Time (mean ± σ): 13.818 ns ± 1.758 ns ┊ GC (mean ± σ): 0.00% ± 0.00% ▃▂▇▅█▇▄▄▁ ▂▂▂▄▃▆▇██████████▇▅▅▃▃▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▂▁▂▂▂▂▂▂▂▁▂▂▂▂ ▃ 12.2 ns Histogram: frequency by time 19.4 ns < Memory estimate: 0 bytes, allocs estimate: 0. julia> let isfirstcall = true, output = 0 global function f_closure() isfirstcall || return output isfirstcall = false return output = 42 end end f_closure (generic function with 1 method) julia> f_closure() 42 julia> @benchmark f_closure() BenchmarkTools.Trial: 10000 samples with 1000 evaluations. Range (min … max): 1.622 ns … 3.031 ns ┊ GC (min … max): 0.00% … 0.00% Time (median): 1.663 ns ┊ GC (median): 0.00% Time (mean ± σ): 1.661 ns ± 0.060 ns ┊ GC (mean ± σ): 0.00% ± 0.00% ▂▄▄▄▃█ ▁▁▁▁▂▃▄▄▄▅▆▅▄▃▄▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▂▃▃▇▇████████▅▄▃▂▂▂▂▂▂▂▂▂▂ ▃ 1.62 ns Histogram: frequency by time 1.68 ns < Memory estimate: 0 bytes, allocs estimate: 0.
Sorry, something went wrong.
Wow, it was a big difference! It shouldn't be hard to change the current code, since we don't have so many solutions.
No branches or pull requests
We currently make use of global variables to avoid recomputing some solutions: see e.g. here:
After discussing the problem in the Discourse, we might consider using a closure as a more elegant approach:
The text was updated successfully, but these errors were encountered: