I have the following code:
function deepcopy_n_times(obj::Set{Int}, n::Int)
for i in 1:n
deepcopy(obj)
end
end
function deepcopy_n_times(obj::Array{Int, 1}, n::Int)
for i in 1:n
deepcopy(obj)
end
end
set = Set{Int}([1, 2, 3, 4, 5])
arr = Array{Int, 1}([1, 2, 3, 4, 5])
num_times = 10000000
@time deepcopy_n_times(arr, num_times)
@time deepcopy_n_times(arr, num_times)
@time deepcopy_n_times(set, num_times)
@time deepcopy_n_times(set, num_times)
The output is:
1.341462 seconds (30.00 M allocations: 4.619 GiB, 17.08% gc time)
1.335890 seconds (30.00 M allocations: 4.619 GiB, 16.63% gc time)
3.896371 seconds (80.00 M allocations: 8.941 GiB, 18.57% gc time)
3.893588 seconds (80.00 M allocations: 8.941 GiB, 18.75% gc time)
Why is copying a set more expensive time-wise? I believe I am betraying my lack of knowledge about how Sets are represented under the hood.