Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import timeit
- setup = """
- from itertools import combinations
- import networkx as nx
- from networkx.generators import fast_gnp_random_graph
- G = fast_gnp_random_graph(200, 0.75, seed=1234)
- def is_subclique(G, nodelist):
- for (u,v) in combinations(nodelist,2): #check each possible pair
- if not G.has_edge(u,v):
- return False #if any edge is missing we're done
- return True #if we get to here, then every edge was there. It's True.
- def is_complete(G):
- n = G.order()
- return n*(n-1)/2 == G.size()
- """
- print(
- "original function took: ",
- min(timeit.Timer("is_subclique(G, [1,2,3,4,5])", setup=setup).repeat(5,10))
- )
- print(
- "new function took: ",
- min(timeit.Timer("is_complete(G.subgraph([1,2,3,4,5]))", setup=setup).repeat(5,10))
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement