I need to construct a dense weighted undirected graph with ~20,000 vertices. Currently, I have the following code
using LightGraphs, SimpleWeightedGraphs function main(n) g = SimpleWeightedGraph(n) for u ∈ vertices(g) for v ∈ (u+1):nv(g) add_edge!(g, u, v, rand()) end end end julia> @time main(10) 0.000014 seconds (22 allocations: 4.969 KiB) julia> @time main(100) 0.005794 seconds (36 allocations: 515.250 KiB) julia> @time main(1000) 86.207979 seconds (48 allocations: 18.017 MiB, 0.01% gc time)
which scales poorly.
Can anyone tell me what am I doing wrong and help me to resolve this performance issue so that I can run it for 20,000 vertices?