Skip to content

Commit

Permalink
Update bench.py
Browse files Browse the repository at this point in the history
  • Loading branch information
nwlandry committed Nov 24, 2024
1 parent 61f5bb1 commit 40aaf54
Showing 1 changed file with 107 additions and 41 deletions.
148 changes: 107 additions & 41 deletions benchmarks/bench.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,41 @@
import pandas as pd
import random

import xgi
import numpy as np
import random
import pandas as pd
import pytest

import xgi

import pytest

def test_construct_from_edgelist(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H.edges.members(),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_construct_from_edgedict(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H.edges.members(dtype=dict),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_construct_from_df(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (xgi.to_bipartite_pandas_dataframe(H),), {}

benchmark.pedantic(xgi.Hypergraph, setup=setup, rounds=10)


def test_node_memberships(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def node_memberships(H):
[H.nodes.memberships(n) for n in H.nodes]

Expand All @@ -45,53 +46,118 @@ def test_edge_members(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def edge_members(H):
[H.edges.members(eid) for eid in H.edges]

benchmark.pedantic(edge_members, setup=setup, rounds=10)


# def setup_benchmarks():
# random.seed(1)
# # but will seed it nevertheless
# np.random.seed(1)
# self.hypergraph = xgi.load_xgi_data("email-enron")
# self.enron_edgelist = xgi.to_hyperedge_list(self.hypergraph)
# self.enron_edgedict = xgi.to_hyperedge_dict(self.hypergraph)
# self.enron_df = xgi.to_bipartite_pandas_dataframe(self.hypergraph)
def test_node_attributes(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def node_attributes(H):
[H.nodes[nid] for nid in H.nodes]

benchmark.pedantic(node_attributes, setup=setup, rounds=10)


def test_edge_attributes(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def edge_attributes(H):
[H.edges[eid] for eid in H.edges]

benchmark.pedantic(edge_attributes, setup=setup, rounds=10)


def test_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

# class CoreHypergraph(Benchmark):
# def setup(self):
# self.hypergraph = xgi.load_xgi_data("email-enron")
# self.enron_edgelist = xgi.to_hyperedge_list(self.hypergraph)
# self.enron_edgedict = xgi.to_hyperedge_dict(self.hypergraph)
# self.enron_df = xgi.to_bipartite_pandas_dataframe(self.hypergraph)
def degree(H):
H.degree()

# def time_node_attributes(self):
# [self.hypergraph.nodes[n] for n in self.hypergraph.nodes]
benchmark.pedantic(degree, setup=setup, rounds=10)

# def time_edge_attributes(self):
# [self.hypergraph.edges[e] for e in self.hypergraph.edges]

# def time_degree(self):
# self.hypergraph.degree()
def test_nodestats_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

# def time_nodestats_degree(self):
# self.hypergraph.nodes.degree.asnumpy()
def degree(H):
H.nodestats.degree.asnumpy()

# def time_edge_size(self):
# self.hypergraph.edges.size.asnumpy()
benchmark.pedantic(degree, setup=setup, rounds=10)

# def time_isolates(self):
# self.hypergraph.nodes.isolates()

# def time_singletons(self):
# self.hypergraph.edges.singletons()
def test_nodestats_degree(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.nodes.degree.asnumpy()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_edge_size(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def degree(H):
H.edges.size.asnumpy()

benchmark.pedantic(degree, setup=setup, rounds=10)


def test_isolates(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def isolates(H):
H.nodes.isolates()

benchmark.pedantic(isolates, setup=setup, rounds=10)


def test_singletons(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def singletons(H):
H.edges.singletons()

benchmark.pedantic(singletons, setup=setup, rounds=10)


def test_copy(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

def copy(H):
H.copy()

benchmark.pedantic(copy, setup=setup, rounds=10)


def test_dual(benchmark):
def setup():
H = xgi.read_hif("email-enron.json")
return (H,), {}

# def time_copy(self):
# self.hypergraph.copy()
def dual(H):
H.dual()

# def time_dual(self):
# self.hypergraph.dual()
benchmark.pedantic(dual, setup=setup, rounds=10)

0 comments on commit 40aaf54

Please sign in to comment.