TextAnalysis.jl icon indicating copy to clipboard operation
TextAnalysis.jl copied to clipboard

Eval can be replaced by getfield in tag_scheme!

Open julbinb opened this issue 4 years ago • 2 comments

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

https://github.com/JuliaText/TextAnalysis.jl/blob/dd67dcff6fe5444a4cbe9f244961cb97ff9c4a65/src/tagging_schemes.jl#L50-L51

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

julbinb avatar Dec 01 '20 16:12 julbinb

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

aviks avatar Dec 01 '20 16:12 aviks

Ok, will do :)

julbinb avatar Dec 01 '20 17:12 julbinb

fixed in https://github.com/JuliaText/TextAnalysis.jl/pull/276/commits/57781294ab34136ee67eba0abb5e6c9b1a0fb733

rssdev10 avatar Oct 26 '23 22:10 rssdev10