wylee / Dijkstar

Graphs, Dijkstra, A*, shortest paths, HTTP graph server
MIT License
56 stars 16 forks source link

Micro op for edge_count() property #20

Closed elliotwutingfeng closed 4 months ago

elliotwutingfeng commented 4 months ago

Possible micro-op for edge_count(), though the sum() comprehension would become slightly less descriptive. Do let me know your thoughts on this.

x = {a:str(a) for a in range(100)}

%timeit sum(len(y) for y in x.values())
2.71 μs ± 11.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
%timeit sum(map(len, x.values()))
1.27 μs ± 4.85 ns per loop (mean ± std. dev. of 7 runs, 1,000,000 loops each)