Closed afniedermayer closed 7 years ago
getfield(x, n) has the same effect as getfield(x, fieldname(Integral, n)), but is faster:
getfield(x, n)
getfield(x, fieldname(Integral, n))
julia> using BenchmarkTools julia> immutable Foo x::Int64 y::Float64 end julia> foo=Foo(2,3) Foo(2,3.0) julia> @benchmark getfield(foo, 1) BenchmarkTools.Trial: memory estimate: 0 bytes allocs estimate: 0 -------------- minimum time: 16.891 ns (0.00% GC) median time: 16.904 ns (0.00% GC) mean time: 17.243 ns (0.00% GC) maximum time: 43.376 ns (0.00% GC) -------------- samples: 10000 evals/sample: 998 julia> @benchmark getfield(foo, fieldname(Foo, 1)) BenchmarkTools.Trial: memory estimate: 0 bytes allocs estimate: 0 -------------- minimum time: 23.665 ns (0.00% GC) median time: 23.709 ns (0.00% GC) mean time: 24.441 ns (0.00% GC) maximum time: 128.074 ns (0.00% GC) -------------- samples: 10000 evals/sample: 996
Good catch! Thank you so much.
getfield(x, n)
has the same effect asgetfield(x, fieldname(Integral, n))
, but is faster: