| 6 | |
| 7 | We expose an unsorted edge iterator. |
| 8 | |
| 9 | Before: |
| 10 | |
| 11 | {{{ |
| 12 | sage: G = Graph(loops=False, multiedges=False) |
| 13 | ....: G.add_edges([(i, (i+85)%100) for i in range(100)]) |
| 14 | ....: G.add_edges([(i, (i+37)%100) for i in range(100)]) |
| 15 | ....: G.add_edges([(i, (i+83)%100) for i in range(100)]) |
| 16 | sage: %timeit edges = list(G.edge_iterator()) |
| 17 | 103 µs ± 10.4 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
| 18 | sage: H = G.copy() |
| 19 | sage: %timeit H == G |
| 20 | 268 µs ± 2.43 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 21 | |
| 22 | sage: G = Graph(loops=False, multiedges=False, sparse=False) |
| 23 | ....: G.add_edges([(i, (i+85)%100) for i in range(100)]) |
| 24 | ....: G.add_edges([(i, (i+37)%100) for i in range(100)]) |
| 25 | ....: G.add_edges([(i, (i+83)%100) for i in range(100)]) |
| 26 | sage: %timeit edges = list(G.edge_iterator()) |
| 27 | 228 µs ± 40.5 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 28 | sage: H = G.copy() |
| 29 | sage: %timeit H == G |
| 30 | 380 µs ± 2.07 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 31 | |
| 32 | |
| 33 | sage: G = Graph(loops=False, multiedges=True) |
| 34 | ....: G.add_edges([(i, (i+85)%100, j) for j in range(20) for i in range(100)]) |
| 35 | ....: G.add_edges([(i, (i+37)%100, j) for j in range(20) for i in range(100)]) |
| 36 | ....: G.add_edges([(i, (i+83)%100, j) for j in range(20) for i in range(100)]) |
| 37 | sage: %timeit edges = list(G.edge_iterator()) |
| 38 | 2.22 ms ± 412 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) |
| 39 | sage: H = G.copy() |
| 40 | sage: %timeit H == G |
| 41 | 2.94 ms ± 51.1 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) |
| 42 | }}} |
| 43 | |
| 44 | After: |
| 45 | |
| 46 | {{{ |
| 47 | sage: G = Graph(loops=False, multiedges=False) |
| 48 | ....: G.add_edges([(i, (i+85)%100) for i in range(100)]) |
| 49 | ....: G.add_edges([(i, (i+37)%100) for i in range(100)]) |
| 50 | ....: G.add_edges([(i, (i+83)%100) for i in range(100)]) |
| 51 | sage: %timeit edges = list(G.edge_iterator()) |
| 52 | 66.2 µs ± 693 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
| 53 | sage: %timeit edges = list(G.edge_iterator(unsorted=True)) |
| 54 | 50.1 µs ± 404 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
| 55 | sage: H = G.copy() |
| 56 | sage: %timeit H == G |
| 57 | 244 µs ± 13.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 58 | |
| 59 | |
| 60 | sage: G = Graph(loops=False, multiedges=False, sparse=False) |
| 61 | ....: G.add_edges([(i, (i+85)%100) for i in range(100)]) |
| 62 | ....: G.add_edges([(i, (i+37)%100) for i in range(100)]) |
| 63 | ....: G.add_edges([(i, (i+83)%100) for i in range(100)]) |
| 64 | sage: %timeit edges = list(G.edge_iterator()) |
| 65 | 125 µs ± 597 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
| 66 | sage: %timeit edges = list(G.edge_iterator(unsorted=True)) |
| 67 | 112 µs ± 1.22 µs per loop (mean ± std. dev. of 7 runs, 10000 loops each) |
| 68 | sage: H = G.copy() |
| 69 | sage: %timeit H == G |
| 70 | 318 µs ± 44.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 71 | |
| 72 | sage: G = Graph(loops=False, multiedges=True) |
| 73 | ....: G.add_edges([(i, (i+85)%100, j) for j in range(20) for i in range(100)]) |
| 74 | ....: G.add_edges([(i, (i+37)%100, j) for j in range(20) for i in range(100)]) |
| 75 | ....: G.add_edges([(i, (i+83)%100, j) for j in range(20) for i in range(100)]) |
| 76 | sage: %timeit edges = list(G.edge_iterator()) |
| 77 | 1.05 ms ± 3.2 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 78 | sage: %timeit edges = list(G.edge_iterator(unsorted=True)) |
| 79 | 1.02 ms ± 40.4 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each) |
| 80 | sage: H = G.copy() |
| 81 | sage: %timeit H == G |
| 82 | 2.81 ms ± 725 µs per loop (mean ± std. dev. of 7 runs, 100 loops each) |
| 83 | }}} |