Rev 4422: Cleanup tools/time_graph.py and add a --quick option. in file:///home/vila/src/bzr/experimental/vila-better-heads/

Vincent Ladeuil v.ladeuil+lp at free.fr
Thu Jun 18 21:00:24 BST 2009


At file:///home/vila/src/bzr/experimental/vila-better-heads/

------------------------------------------------------------
revno: 4422
revision-id: v.ladeuil+lp at free.fr-20090618200024-fdrav7hxlz3soot2
parent: v.ladeuil+lp at free.fr-20090618194524-poedor61th3op5dm
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: vila-better-heads
timestamp: Thu 2009-06-18 22:00:24 +0200
message:
  Cleanup tools/time_graph.py and add a --quick option.
-------------- next part --------------
=== modified file 'tools/time_graph.py'
--- a/tools/time_graph.py	2009-06-18 09:51:38 +0000
+++ b/tools/time_graph.py	2009-06-18 20:00:24 +0000
@@ -16,13 +16,15 @@
 from bzrlib.ui import text
 
 p = optparse.OptionParser()
+p.add_option('--quick', default=False, action='store_true')
 p.add_option('--max-combinations', default=500, type=int)
 p.add_option('--lsprof', default=None, type=str)
 opts, args = p.parse_args(sys.argv[1:])
+
 trace.enable_default_logging()
 ui.ui_factory = text.TextUIFactory()
 
-t1 = time.clock()
+begin = time.clock()
 if len(args) >= 1:
     b = branch.Branch.open(args[0])
 else:
@@ -34,9 +36,9 @@
                          if p[1] is not None)
 finally:
     b.unlock()
-t2 = time.clock()
+end = time.clock()
 
-print 'Found %d nodes, loaded in %.3fs' % (len(parent_map), t2-t1)
+print 'Found %d nodes, loaded in %.3fs' % (len(parent_map), end - begin)
 
 def all_heads_comp(g, combinations):
     h = []
@@ -49,6 +51,7 @@
     finally:
         pb.finished()
     return h
+
 combinations = []
 # parents = parent_map.keys()
 # for p1 in parents:
@@ -67,33 +70,48 @@
     combinations = random.sample(combinations, opts.max_combinations)
 
 print '      %d combinations' % (len(combinations),)
-t1 = time.clock()
-known_g = _known_graph_py.KnownGraph(parent_map)
-if opts.lsprof is not None:
-    h_known = commands.apply_lsprofiled(opts.lsprof,
-        all_heads_comp, known_g, combinations)
-else:
-    h_known = all_heads_comp(known_g, combinations)
-t2 = time.clock()
-print "Known: %.3fs" % (t2-t1,)
-print "  %s" % (graph._counters,)
-t1 = time.clock()
-known_g = _known_graph_pyx.KnownGraph(parent_map)
-if opts.lsprof is not None:
-    h_known = commands.apply_lsprofiled(opts.lsprof,
-        all_heads_comp, known_g, combinations)
-else:
-    h_known = all_heads_comp(known_g, combinations)
-t2 = time.clock()
-print "Known (pyx): %.3fs" % (t2-t1,)
-print "  %s" % (graph._counters,)
-simple_g = graph.Graph(graph.DictParentsProvider(parent_map))
-graph._counters[1] = 0
-graph._counters[2] = 0
-h_simple = all_heads_comp(simple_g, combinations)
-t3 = time.clock()
-print "Orig: %.3fs" % (t3-t2,)
-print "  %s" % (graph._counters,)
-if h_simple != h_known:
-    import pdb; pdb.set_trace()
-print 'ratio: %.3fs' % ((t2-t1) / (t3-t2))
+
+def combi_graph(graph_klass, comb):
+    # DEBUG
+    graph._counters[1] = 0
+    graph._counters[2] = 0
+
+    begin = time.clock()
+    g = graph_klass(parent_map)
+    if opts.lsprof is not None:
+        heads = commands.apply_lsprofiled(opts.lsprof, all_heads_comp, g, comb)
+    else:
+        heads = all_heads_comp(g, comb)
+    end = time.clock()
+    return dict(elapsed=(end - begin), graph=g, heads=heads)
+
+def report(name, g):
+    print '%s: %.3fs' % (name, g['elapsed'])
+    counters_used = False
+    for c in graph._counters:
+        if c:
+            counters_used = True
+    if counters_used:
+        print '  %s' % (graph._counters,)
+
+known_python = combi_graph(_known_graph_py.KnownGraph, combinations)
+report('Known', known_python)
+
+known_pyrex = combi_graph(_known_graph_pyx.KnownGraph, combinations)
+report('Known (pyx)', known_pyrex)
+
+def _simple_graph(parent_map):
+    return graph.Graph(graph.DictParentsProvider(parent_map))
+
+if opts.quick:
+    if known_python['heads'] != known_pyrex['heads']:
+        import pdb; pdb.set_trace()
+    print 'ratio: %.3fs' % (known_pyrex['elapsed'] / known_python['elapsed'])
+else:
+    orig = combi_graph(_simple_graph, combinations)
+    report('Orig', orig)
+
+    if orig['heads'] != known_pyrex['heads']:
+        import pdb; pdb.set_trace()
+
+    print 'ratio: %.3fs' % (known_pyrex['elapsed'] / orig['elapsed'])



More information about the bazaar-commits mailing list