-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Profiler; optimize generate_edge_and_wait_values (#14)
* new profiler method * test perf script * indexing optimization * drop sort operations * update comments * rename profile script * undo change in file name and dir * py 3.5 compatable * update test_generate_summary_graph_elements * drop f string
- Loading branch information
Showing
4 changed files
with
96 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
test: | ||
PYTHONPATH=. MPLBACKEND="agg" coverage run --source peartree -m py.test --verbose | ||
|
||
performance: | ||
PYTHONPATH=. MPLBACKEND="agg" pytest profiler/test_graph_assembly.py -s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
from time import time | ||
|
||
from peartree.graph import generate_empty_md_graph, populate_graph | ||
from peartree.paths import get_representative_feed | ||
from peartree.summarizer import (generate_edge_and_wait_values, | ||
generate_summary_edge_costs, | ||
generate_summary_wait_times) | ||
|
||
|
||
def fixture(filename): | ||
return os.path.join('tests', 'fixtures', filename) | ||
|
||
|
||
def test_feed_to_graph_performance(): | ||
# Replicate the original workflow of the graph creation path | ||
# but open up to expose to benchmarking/performance profiling | ||
start = 7 * 60 * 60 | ||
end = 10 * 60 * 60 | ||
|
||
print('Running time profiles on each major ' | ||
'function in graph generation workflow') | ||
|
||
a = time() | ||
path = fixture('samtrans-2017-11-28.zip') | ||
feed = get_representative_feed(path) | ||
elapsed = round(time() - a, 2) | ||
print('Perf of get_representative_feed: {}s'.format(elapsed)) | ||
|
||
fl = len(feed.routes) | ||
print('Iteration on {} routes.'.format(fl)) | ||
|
||
a = time() | ||
(all_edge_costs, | ||
all_wait_times) = generate_edge_and_wait_values(feed, | ||
start, | ||
end) | ||
elapsed = round(time() - a, 2) | ||
print('Perf of generate_edge_and_wait_values: {}s'.format(elapsed)) | ||
|
||
a = time() | ||
summary_edge_costs = generate_summary_edge_costs(all_edge_costs) | ||
elapsed = round(time() - a, 2) | ||
print('Perf of generate_summary_edge_costs: {}s'.format(elapsed)) | ||
|
||
a = time() | ||
wait_times_by_stop = generate_summary_wait_times(all_wait_times) | ||
elapsed = round(time() - a, 2) | ||
print('Perf of generate_summary_wait_times: {}s'.format(elapsed)) | ||
|
||
a = time() | ||
G = generate_empty_md_graph('foo') | ||
elapsed = round(time() - a, 2) | ||
print('Perf of generate_empty_md_graph: {}s'.format(elapsed)) | ||
|
||
a = time() | ||
G = populate_graph(G, | ||
'bar', | ||
feed, | ||
wait_times_by_stop, | ||
summary_edge_costs, | ||
50, | ||
4.5) | ||
elapsed = round(time() - a, 2) | ||
print('Perf of populate_graph: {}s'.format(elapsed)) |