From 40aaf54e193d9a977fb1da126949e2d6477ee671 Mon Sep 17 00:00:00 2001 From: Nicholas Landry Date: Sun, 24 Nov 2024 16:51:05 -0500 Subject: [PATCH] Update bench.py --- benchmarks/bench.py | 148 ++++++++++++++++++++++++++++++++------------ 1 file changed, 107 insertions(+), 41 deletions(-) diff --git a/benchmarks/bench.py b/benchmarks/bench.py index af526b3f..f7e49e26 100644 --- a/benchmarks/bench.py +++ b/benchmarks/bench.py @@ -1,17 +1,17 @@ -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) @@ -19,7 +19,7 @@ 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) @@ -27,14 +27,15 @@ 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] @@ -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)