Thatβs nice!
The list comprehension is very natural in Python though, which can bias oneβs appreciation.
Of dubious interest, but possibly worthy of note:
using BenchmarkTools
const dict = Dict(i => j for (j,i) in enumerate('A':'Z'))
const keys = collect('B':'Y')
@benchmark get.(Ref(dict), keys, missing)
BenchmarkTools.Trial: 10000 samples with 590 evaluations.
Range (min β¦ max): 200.120 ns β¦ 1.306 ΞΌs β GC (min β¦ max): 0.00% β¦ 82.69%
Time (median): 210.534 ns β GC (median): 0.00%
Time (mean Β± Ο): 219.662 ns Β± 55.169 ns β GC (mean Β± Ο): 1.39% Β± 4.74%
βββββββββ
ββββββββββ β
βββββββββββββββββββββββββββββββββ
ββββββββ
ββ
β
β
ββ
β
ββ
β
β
βββββ
ββ
β β
200 ns Histogram: log(frequency) by time 313 ns <
Memory estimate: 280 bytes, allocs estimate: 3.
@benchmark [haskey(dict, k) ? dict[k] : missing for k in keys]
BenchmarkTools.Trial: 10000 samples with 257 evaluations.
Range (min β¦ max): 299.370 ns β¦ 3.284 ΞΌs β GC (min β¦ max): 0.00% β¦ 89.86%
Time (median): 307.296 ns β GC (median): 0.00%
Time (mean Β± Ο): 323.600 ns Β± 101.617 ns β GC (mean Β± Ο): 1.00% Β± 3.26%
ββ
βββββ βββββ β
βββββββββββββββββββββββββββ
β
ββ
βββββββ
β
ββββ
β
β
β
β
βββββββββββββββ β
299 ns Histogram: log(frequency) by time 555 ns <
Memory estimate: 256 bytes, allocs estimate: 1.