16
16
from bzrlib.ui import text
18
18
p = optparse.OptionParser()
19
p.add_option('--quick', default=False, action='store_true')
19
20
p.add_option('--max-combinations', default=500, type=int)
20
21
p.add_option('--lsprof', default=None, type=str)
21
22
opts, args = p.parse_args(sys.argv[1:])
22
24
trace.enable_default_logging()
23
25
ui.ui_factory = text.TextUIFactory()
26
29
b = branch.Branch.open(args[0])
61
66
for revision_id, parent_ids in parent_map.iteritems():
62
67
if parent_ids is not None and len(parent_ids) > 1:
63
68
combinations.append(parent_ids)
69
# The largest portion of the graph that has to be walked for a heads() check
70
# combinations = [('john@arbash-meinel.com-20090312021943-tu6tcog48aiujx4s',
71
# 'john@arbash-meinel.com-20090312130552-09xa2xsitf6rilzc')]
64
72
if opts.max_combinations > 0 and len(combinations) > opts.max_combinations:
65
73
combinations = random.sample(combinations, opts.max_combinations)
67
75
print ' %d combinations' % (len(combinations),)
69
known_g = _known_graph_py.KnownGraph(parent_map)
70
if opts.lsprof is not None:
71
h_known = commands.apply_lsprofiled(opts.lsprof,
72
all_heads_comp, known_g, combinations)
74
h_known = all_heads_comp(known_g, combinations)
76
print "Known: %.3fs" % (t2-t1,)
77
print " %s" % (graph._counters,)
79
known_g = _known_graph_pyx.KnownGraph(parent_map)
80
if opts.lsprof is not None:
81
h_known = commands.apply_lsprofiled(opts.lsprof,
82
all_heads_comp, known_g, combinations)
84
h_known = all_heads_comp(known_g, combinations)
86
print "Known (pyx): %.3fs" % (t2-t1,)
87
print " %s" % (graph._counters,)
88
simple_g = graph.Graph(graph.DictParentsProvider(parent_map))
89
graph._counters[1] = 0
90
graph._counters[2] = 0
91
h_simple = all_heads_comp(simple_g, combinations)
93
print "Orig: %.3fs" % (t3-t2,)
94
print " %s" % (graph._counters,)
95
if h_simple != h_known:
96
import pdb; pdb.set_trace()
97
print 'ratio: %.3fs' % ((t2-t1) / (t3-t2))
77
def combi_graph(graph_klass, comb):
79
graph._counters[1] = 0
80
graph._counters[2] = 0
83
g = graph_klass(parent_map)
84
if opts.lsprof is not None:
85
heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
87
heads = all_heads_comp(g, comb)
89
return dict(elapsed=(end - begin), graph=g, heads=heads)
92
print '%s: %.3fs' % (name, g['elapsed'])
94
for c in graph._counters:
98
print ' %s' % (graph._counters,)
100
known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
101
report('Known', known_python)
103
known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)
104
report('Known (pyx)', known_pyrex)
106
def _simple_graph(parent_map):
107
return graph.Graph(graph.DictParentsProvider(parent_map))
110
if known_python['heads'] != known_pyrex['heads']:
111
import pdb; pdb.set_trace()
112
print 'ratio: %.1f:1 faster' % (
113
known_python['elapsed'] / known_pyrex['elapsed'],)
115
orig = combi_graph(_simple_graph, combinations)
118
if orig['heads'] != known_pyrex['heads']:
119
import pdb; pdb.set_trace()
121
print 'ratio: %.1f:1 faster' % (
122
orig['elapsed'] / known_pyrex['elapsed'],)