I've been using networkx to simply create a graph and check the connected
components.  The bottleneck of the operation is the creation of the edges.

I've heard that graph-tool is very efficient so I've replaces the code with
a graph-tool graph.
To my surprise, the creation of a graph-tool graph is MUCH slower than that
of a networkx graph.

Am I doing something wrong?

I've created a small sample program (at the bottom of this message) to test
this speed...
  it creates a graph in a very natural way:  pairs of objects that should be
connected by an edge are iterated through.  We happen to give every possible
pair of objects in this example so the complete graph is created.

Here is runsnake image of where the running-time is going:

<http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/file/n4026108/runsnake_compare.png>
 

The Code:

#!/usr/bin/python
"""
Create graphs in networkx and graph-tool.
"""

import networkx as nx
from graph_tool.all import *

from itertools import combinations


def graph_tool_create():
  """ Create a graph_tool graph given a list of pairs. """
  G = Graph(directed=False)       
  objectset = set()
  for o1,o2 in get_pairs_of_objects():
    if(o1 not in objectset):
      u = G.add_vertex()
      objectset.add(o1)
    if(o2 not in objectset):
      v = G.add_vertex()
      objectset.add(o2)

    G.add_edge(u,v)


def nx_create():
  """ Create a graph_tool graph given a list of pairs. """
  G = nx.Graph()       
  for o1,o2 in get_pairs_of_objects():
    G.add_edge(o1,o2)


def get_pairs_of_objects():
  """ Generate pairs of objects.  """
  n = 5000
  for a,b in combinations(range(n),2):
    yield a,b


graph_tool_create()
nx_create()




--
View this message in context: 
http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/efficiency-of-graph-creation-tp4026108.html
Sent from the Main discussion list for the graph-tool project mailing list 
archive at Nabble.com.
_______________________________________________
graph-tool mailing list
[email protected]
http://lists.skewed.de/mailman/listinfo/graph-tool

Reply via email to