Skip to content

Instantly share code, notes, and snippets.

@dschult
dschult / benchmark.py
Last active July 8, 2022 18:37
A script to time simple operations with various graph classes. The output is just text tables of the timing results. The code itself is pretty ugly, but it gets the job done.
from timeit import Timer
# This is gratefully modeled after the benchmarks found in
# the numpy svn repository. http://svn.scipy.org/svn/numpy/trunk
import networkx as nx
class Benchmark(object):
"""
Benchmark a method or simple bit of code using different Graph classes.
@dschult
dschult / graphview.py
Last active December 31, 2015 19:34
NodeView and EdgesView classes for NetworkX Graphs
from __future__ import print_function
class NodesView(object):
def __init__(self, graph, data=False, default=None):
self.G = graph
self.data = data
self.default = default
def __iter__(self):
data=self.data
if data is True: