Skip to content

Instantly share code, notes, and snippets.

@OndrejSlamecka
Last active March 31, 2023 19:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OndrejSlamecka/6141522e3c1e76b870174d54978f3227 to your computer and use it in GitHub Desktop.
Save OndrejSlamecka/6141522e3c1e76b870174d54978f3227 to your computer and use it in GitHub Desktop.
julia> using BenchmarkTools
julia> using Dictionaries
julia> function f(d)
for _ = 1:1000
set!(d, 1, 1)
unset!(d, 1)
end
end
f (generic function with 1 method)
julia> @benchmark f(d) setup=(d=Dict{Int,Int}())
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 15.860 μs … 1.987 ms ┊ GC (min … max): 0.00% … 98.90%
Time (median): 17.323 μs ┊ GC (median): 0.00%
Time (mean ± σ): 19.957 μs ± 52.206 μs ┊ GC (mean ± σ): 7.36% ± 2.79%
▅▆▇███▇▇▅▅▄▃▂▁▁▁ ▁▁ ▁ ▁▁▁▁▁▂▂▃▂▂▂▃▂▂▂▂▁▁▁▁ ▃
▇█████████████████████████████████████████████▇█▇▆▇▅▇▇▆▇▅▄▅ █
15.9 μs Histogram: log(frequency) by time 29.2 μs <
Memory estimate: 37.61 KiB, allocs estimate: 249.
julia> @benchmark f(d) setup=(d=Dictionary{Int,Int}())
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 33.273 μs … 172.287 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 34.897 μs ┊ GC (median): 0.00%
Time (mean ± σ): 35.955 μs ± 4.889 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
▁▃▆▆█▆▄▂▁ ▁ ▁ ▁
██████████▆▆▆▆▆▆▆▇▆▆▆▆▅▆▅▇▆██▇▆▅▅▄▅▄▄▄▅▃▄▄▄▃▄▃▄▃▃▃▃▃▄▃▆██▆▆▅ █
33.3 μs Histogram: log(frequency) by time 55.5 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
julia> @benchmark f(d) setup=(d=UnorderedDictionary{Int,Int}())
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 10.149 μs … 76.165 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 10.359 μs ┊ GC (median): 0.00%
Time (mean ± σ): 10.647 μs ± 1.665 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
▇█▇▃▂▃▁▁▁▁ ▁▁ ▂
███████████████▆▅▆▆▆▅▄▅█▇▆████▆▆▅▅▅▅▅▅▆▅▆▅▄▅▅▆▅▅▃▅▅▅▁▄▃▅▄▆▅ █
10.1 μs Histogram: log(frequency) by time 16.5 μs <
Memory estimate: 0 bytes, allocs estimate: 0.
@OndrejSlamecka
Copy link
Author

Probably caused by this rehash triggered by the number of deletes https://github.com/JuliaLang/julia/blob/580f51d26fe2cff97e6ee7a8af12c42ff9ed272b/base/dict.jl#L366

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment