Igraph: Why Is Add_edge Function So Slow Ompared To Add_edges?
Solution 1:
The reason is that igraph uses an indexed edge list as its data structure in the C layer. The index makes it possible to query the neighbors of a specific vertex in constant time. This is good if your graph rarely changes, but it becomes a burden when the modification operations are far more frequent than the queries, since whenever you add or remove an edge, you have to update the index. So, every call to add_edge
will make igraph reindex its internal data structures. The upside is that if you have to rebuild the index anyway, you can just as well add many edges using add_edges
with approximately the same cost. So, in your first code example, you rebuild the index 30000 times, while in the second example, you rebuild the index only once.
By the way, what you are doing could be done even faster using Graph.Erdos_Renyi(n=10000, m=30000)
.
Post a Comment for "Igraph: Why Is Add_edge Function So Slow Ompared To Add_edges?"