16
from breezy.ui import text
18
p = optparse.OptionParser()
19
p.add_option('--quick', default=False, action='store_true')
20
p.add_option('--max-combinations', default=500, type=int)
21
p.add_option('--lsprof', default=None, type=str)
22
opts, args = p.parse_args(sys.argv[1:])
24
trace.enable_default_logging()
25
ui.ui_factory = text.TextUIFactory()
29
b = branch.Branch.open(args[0])
31
b = branch.Branch.open('.')
33
g = b.repository.get_graph()
34
parent_map = dict(p for p in g.iter_ancestry([b.last_revision()])
38
print('Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin))
40
def all_heads_comp(g, combinations):
42
with ui.ui_factory.nested_progress_bar() as pb:
43
for idx, combo in enumerate(combinations):
45
pb.update('proc', idx, len(combinations))
46
h.append(g.heads(combo))
50
# parents = parent_map.keys()
52
# for p2 in random.sample(parents, 10):
53
# combinations.append((p1, p2))
54
# Times for random sampling of 10x1150 of bzrtools
57
# Times for 500 'merge parents' from bzr.dev
60
for revision_id, parent_ids in parent_map.iteritems():
61
if parent_ids is not None and len(parent_ids) > 1:
62
combinations.append(parent_ids)
63
# The largest portion of the graph that has to be walked for a heads() check
64
# combinations = [('john@arbash-meinel.com-20090312021943-tu6tcog48aiujx4s',
65
# 'john@arbash-meinel.com-20090312130552-09xa2xsitf6rilzc')]
66
if opts.max_combinations > 0 and len(combinations) > opts.max_combinations:
67
combinations = random.sample(combinations, opts.max_combinations)
69
print(' %d combinations' % (len(combinations),))
71
def combi_graph(graph_klass, comb):
73
graph._counters[1] = 0
74
graph._counters[2] = 0
77
g = graph_klass(parent_map)
78
if opts.lsprof is not None:
79
heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
81
heads = all_heads_comp(g, comb)
83
return dict(elapsed=(end - begin), graph=g, heads=heads)
86
print('%s: %.3fs' % (name, g['elapsed']))
88
for c in graph._counters:
92
print(' %s' % (graph._counters,))
94
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
95
report('Known', known_python)
97
known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)
98
report('Known (pyx)', known_pyrex)
100
def _simple_graph(parent_map):
101
return graph.Graph(graph.DictParentsProvider(parent_map))
104
if known_python['heads'] != known_pyrex['heads']:
105
import pdb; pdb.set_trace()
106
print('ratio: %.1f:1 faster' % (
107
known_python['elapsed'] / known_pyrex['elapsed'],))
109
orig = combi_graph(_simple_graph, combinations)
112
if orig['heads'] != known_pyrex['heads']:
113
import pdb; pdb.set_trace()
115
print('ratio: %.1f:1 faster' % (
116
orig['elapsed'] / known_pyrex['elapsed'],))