Skip to content
New issue

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

Eval can be replaced by getfield in smooth #120

Closed
julbinb opened this issue Dec 1, 2020 · 1 comment
Closed

Eval can be replaced by getfield in smooth #120

julbinb opened this issue Dec 1, 2020 · 1 comment

Comments

@julbinb
Copy link

julbinb commented Dec 1, 2020

getfield would be more efficient than eval in getting the value of a variable/function name here:

smoother = eval(Symbol(forecast_smoother(m), "_smoother"))

Toy example:

julia> using BenchmarkTools

julia> foo = 42
42

julia> @btime eval(Symbol("foo"))
  44.230 ns (0 allocations: 0 bytes)
42

julia> @btime getfield(Main, Symbol("foo"))
  1.180 ns (0 allocations: 0 bytes)
42
@chenwilliam77
Copy link
Collaborator

Thanks for this! This change will be added to the next release of the package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants