Graph-tool surprisingly slow compared to Networkx : <p>After looking at the impressive <a href="https://graph-tool.skewed.de/performance" rel="noreferrer">performance comparison</a>, I decided that I would give a try to graph-tool. So for comparison, I wrote codes to generate a random tree using both packages. </p>

<p>The graph-tool code:</p>

<pre><code>import numpy as np
import graph_tool.all as gt

# construct an initial graph with two nodes and one link
n = 5000
G = gt.Graph(directed = False)
G.add_edge(0, 1)

for t in range(2, n):
    # connect the new vertex to one of the old vertices randomly
    G.add_edge(np.random.choice(range(t)), t)
</code></pre>

<p>The Networkx code:</p>

<pre><code>import networkx as nx
import numpy as np

n = 5000
# initial graph
G = nx.Graph()
G.add_edge(0, 1)

for t in range(2, n):
    G.add_edge(t, np.random.choice(range(t)))
</code></pre>

<p>The graph-tool takes around 14 seconds on my 4-core machine whereas networkx takes less than 2 seconds on the same machine! Am I missing something obvious?</p>

<p>Thanks in advance.</p>
