JuliaText / TextAnalysis.jl

Julia package for text analysis
Other
373 stars 95 forks source link

Eval can be replaced by getfield in tag_scheme! #242

Closed julbinb closed 8 months ago

julbinb commented 3 years ago

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
aviks commented 3 years ago

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

julbinb commented 3 years ago

Ok, will do :)

rssdev10 commented 8 months ago

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