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 tag_scheme! #242

Closed
julbinb opened this issue Dec 1, 2020 · 3 comments
Closed

Eval can be replaced by getfield in tag_scheme! #242

julbinb opened this issue Dec 1, 2020 · 3 comments

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:

current_scheme = eval(Symbol(current_scheme))()
new_scheme = eval(Symbol(new_scheme))()

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
@aviks
Copy link
Member

aviks commented Dec 1, 2020

Thanks, yes, this code if probably from before getfield existed. I'd be grateful for a PR.

@julbinb
Copy link
Author

julbinb commented Dec 1, 2020

Ok, will do :)

@rssdev10
Copy link
Collaborator

fixed in 5778129

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

Successfully merging a pull request may close this issue.

3 participants