Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sagemathgh-39300: faster method
__mul__
for graphs
Instead of $n-1$ additions of graphs, we use a logarithmic number of additions of graphs to compute $G * n$. Before ```sage sage: def test(G): ....: for i in [1, 2, 3, 4, 5, 10, 15, 20, 50, 100]: ....: t = walltime() ....: for _ in range(10): ....: H = G * i ....: t = walltime() - t ....: print(f"{i}\t {round(t/10, 5)}") sage: test(Graph([(0, 1)])) 1 3e-05 2 0.00011 3 0.00016 4 0.00024 5 0.00032 10 0.00072 15 0.00108 20 0.00139 50 0.00437 100 0.01272 sage: test(graphs.PetersenGraph()) 1 5e-05 2 0.00017 3 0.00028 4 0.00042 5 0.00055 10 0.00148 15 0.0024 20 0.00343 50 0.01802 100 0.07057 ``` Now ```sage sage: test(Graph([(0, 1)])) 1 3e-05 2 0.0001 3 0.00018 4 0.00018 5 0.00025 10 0.00035 15 0.00053 20 0.00043 50 0.00083 100 0.00118 sage: test(graphs.PetersenGraph()) 1 4e-05 2 0.00015 3 0.00028 4 0.00026 5 0.00041 10 0.00066 15 0.00117 20 0.00094 50 0.0024 100 0.00448 ``` ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. --> - [x] The title is concise and informative. - [x] The description explains in detail what this PR is about. - [ ] I have linked a relevant issue or discussion. - [ ] I have created tests covering the changes. - [ ] I have updated the documentation and checked the documentation preview. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on. For example, --> <!-- - sagemath#12345: short description why this is a dependency --> <!-- - sagemath#34567: ... --> URL: sagemath#39300 Reported by: David Coudert Reviewer(s): Frédéric Chapoton
- Loading branch information