Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #33743: Faster random tree generator
We use a heap to replace a loop searching for the vertex with smallest index and count 0 with a pop operation. The change is safe as it does not modify the order in which vertices are considered. This way, the generator is no longer quadratic. Before (with #33579) {{{ sage: %time T = graphs.RandomTree(10, seed=0) CPU times: user 380 µs, sys: 84 µs, total: 464 µs Wall time: 448 µs sage: %time T = graphs.RandomTree(100, seed=0) CPU times: user 1.44 ms, sys: 118 µs, total: 1.56 ms Wall time: 1.57 ms sage: %time T = graphs.RandomTree(1000, seed=0) CPU times: user 46.1 ms, sys: 2.34 ms, total: 48.5 ms Wall time: 47.1 ms sage: %time T = graphs.RandomTree(10000, seed=0) CPU times: user 2.75 s, sys: 14.8 ms, total: 2.77 s Wall time: 2.78 s }}} After {{{ sage: %time T = graphs.RandomTree(10, seed=0) CPU times: user 363 µs, sys: 60 µs, total: 423 µs Wall time: 407 µs sage: %time T = graphs.RandomTree(100, seed=0) CPU times: user 1.19 ms, sys: 629 µs, total: 1.82 ms Wall time: 1.26 ms sage: %time T = graphs.RandomTree(1000, seed=0) CPU times: user 6.52 ms, sys: 156 µs, total: 6.68 ms Wall time: 6.68 ms sage: %time T = graphs.RandomTree(10000, seed=0) CPU times: user 59.3 ms, sys: 3.63 ms, total: 63 ms Wall time: 62 ms }}} URL: https://trac.sagemath.org/33743 Reported by: dcoudert Ticket author(s): David Coudert Reviewer(s): Travis Scrimshaw
- Loading branch information