This page shows a succinct performance comparison between graph-tool and two other popular graph libraries with Python bindings, igraph and NetworkX. NetworkX is a pure-python implementation, whereas igraph is implemented in C. Here we select a few representative algorithms which are implemented in all three libraries, and test them on the same graph.
The graph used here is the strongly connected component of the PGP web of trust network circa November 2009. It is a directed graph, with N=39,796 vertices and E=301,498 edges. The network, test scripts and raw outputs can be downloaded at the bottom of the page.
For this test we used graph-tool 2.11, igraph 0.7.1 and NetworkX 1.10.
The functions were called several times, and the average time taken per function call was computed and shown below. All results are for the same Intel(R) Core(TM) i7-5500U CPU @ 2.40GHz with 4 cores. In the second column are shown the results for graph-tool with OpenMP enabled using 4 threads, and the third column shows the results using only one core.
|Algorithm||graph-tool (4 cores)||graph-tool (1 core)||igraph||NetworkX|
|Single-source shortest path||0.004 s||0.004 s||0.012 s||0.152 s|
|PageRank||0.029 s||0.045 s||0.093 s||3.949 s|
|K-core||0.014 s||0.014 s||0.022 s||0.714 s|
|Minimum spanning tree||0.040 s||0.031 s||0.044 s||2.045 s|
|Betweenness||244.3 s (~4.1 mins)||601.2 s (~10 mins)|| 946.8 s (edge) |
+ 353.9 s (vertex)
(~ 21.6 mins)
| 32676.4 s (edge) 22650.4 s (vertex) |
Both graph-tool and igraph seem to deliver overall comparable performance, at least when OpenMP is disabled. However, even in this case graph-tool seems to be slightly faster systematically.
As expected, graph-tool becomes faster by a constant factor when OpenMP is enabled on algorithms which run in parallel (PageRank and Betweenness), and thus beats igraph in these cases by a significant margin, which would increase even further in a machine with more cores.
NetworkX, on the other hand, comes at a distant third with running times in the order of 20 to 170 times slower than graph-tool. This is mostly due to its pure Python implementation, which is known in general to be substantially slower than C/C++ (see here, here and here for further comparisons).
One must remember that performance alone is not the only issue which should be considered. All these libraries have their own advantages and disadvantages, which need to be considered in detail when deciding what is the best library to use. Here are a couple of important facts:
Additionally, these libraries have different APIs and handle things slightly differently, and they may appeal to different user tastes. Furthermore the set of algorithms which is implemented is not identical. For instance, graph-tool has graph filtering, more extensive flow algorithms, stochastic blockmodel inference, and interactive graph drawing, to name a few unique features. However, both NetworkX and igraph have their own unique features and algorithms which graph-tool currently lacks, and a detailed point-for-point comparison it is out of the scope of this brief analysis. In the end, it is up to the user to make a more detailed comparison and decide what is more appropriate.
Source Network: pgp.xml.gz, "The strongly connected component of the PGP network circa 2009."
This page was last updated on 27 Oct 2015.