Ticket #7571 (closed enhancement: fixed)
use more dicts in graph.py
| Reported by: | ylchapuy | Owned by: | rlm |
|---|---|---|---|
| Priority: | minor | Milestone: | sage-4.3 |
| Component: | graph theory | Keywords: | |
| Cc: | Work issues: | ||
| Report Upstream: | N/A | Reviewers: | Robert Miller |
| Authors: | Yann Laigle-Chapuy | Merged in: | sage-4.3.alpha1 |
| Dependencies: | Stopgaps: |
Description
This patch improves 3 methods in graph.py:
- connected_components: we use python set instead of lists to enable fast lookup
- blocks_and_cut_vertices: using dicts instead of lists enable us to avoid relabeling
- girth: idem
Attachments
Change History
comment:2 Changed 3 years ago by ylchapuy
- Priority changed from major to minor
- Status changed from new to needs_review
comment:3 Changed 3 years ago by rlm
- Status changed from needs_review to positive_review
Your benchmarks would be more convincing if you used set_random_seed beforehand, so you're actually testing the same "random" graph.
The changes to the code look good, and the speedups are impressive.
comment:4 Changed 3 years ago by ylchapuy
that's true, benchmarks are not very convincing. Here are new ones:
before:
sage: set_random_seed(42) sage: g=graphs.RandomGNP(20000,.00005) sage: time g.girth() CPU times: user 17.55 s, sys: 0.07 s, total: 17.62 s Wall time: 17.83 s 16 sage: time g.connected_components_number() CPU times: user 8.40 s, sys: 0.08 s, total: 8.48 s Wall time: 8.72 s 9810 sage: set_random_seed(42) sage: g=graphs.RandomGNP(10000,.005) sage: time b=g.blocks_and_cut_vertices() CPU times: user 17.19 s, sys: 0.44 s, total: 17.63 s Wall time: 17.98 s
after:
sage: set_random_seed(42) sage: g=graphs.RandomGNP(20000,.00005) sage: time g.girth() CPU times: user 2.15 s, sys: 0.00 s, total: 2.16 s Wall time: 2.15 s 16 sage: time g.connected_components_number() CPU times: user 0.32 s, sys: 0.00 s, total: 0.32 s Wall time: 0.32 s 9810 sage: set_random_seed(42) sage: g=graphs.RandomGNP(10000,.005) sage: time b=g.blocks_and_cut_vertices() CPU times: user 10.22 s, sys: 0.04 s, total: 10.27 s Wall time: 10.57 s
Note: See
TracTickets for help on using
tickets.


for the record:
Before:
After:
And more importantly:
before:
after: