我很惊讶:
import igraph
import random,time
start_time = time.time()
G = igraph.Graph(directed = True)
G.add_vertices(10000)
for i in range(30000):
G.add_edge(random.randint(0,9999),random.randint(0,9999))
print "done in " + str(int(time.time() - start_time)) + " seconds"
返回在63秒内完成
而
import igraph
import random,time
start_time = time.time()
G = igraph.Graph(directed = True)
G.add_vertices(10000)
edges = []
for i in range(30000):
edges += [(random.randint(0,9999))]
G.add_edges(edges)
print "done in " + str(int(time.time() - start_time)) + " seconds"
在0秒内完成返回.
项目中有人知道为什么吗?