嗨!我想获得我的函数( test(G) )的执行时间。当我使用 Timer 时,我需要编写对象的类型: "test(% ?? )" %G 这里是有向图。我怎样才能做到这一点?
from networkx import nx
def test(G):
for e in G.edges_iter():
print(e)
if __name__=='__main__':
from timeit import Timer
G = nx.DiGraph()
G.add_edges_from([(1,2),(4,5)])
t = Timer("test(% ?? )"%G,"from __main__ import test")
print( t.timeit(1))