Rev 1: A simple plugin for benchmarking the speed of patience_diff. in http://bzr.arbash-meinel.com/plugins/bench_patience

John Arbash Meinel john at arbash-meinel.com
Tue Dec 4 15:43:19 GMT 2007


At http://bzr.arbash-meinel.com/plugins/bench_patience

------------------------------------------------------------
revno: 1
revision-id:john at arbash-meinel.com-20071204154317-awmijsr5fixg7dg1
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: bench_patience
timestamp: Tue 2007-12-04 09:43:17 -0600
message:
  A simple plugin for benchmarking the speed of patience_diff.
added:
  __init__.py                    __init__.py-20071204154123-hrdofqdugj0iwxcy-1
-------------- next part --------------
=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2007-12-04 15:43:17 +0000
@@ -0,0 +1,72 @@
+# Copyright (C) 2007 Canonical Ltd
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+"""Benchmark the patience_diff algorithm."""
+
+version_info = (0, 1, 0, 'dev', 0)
+
+import time
+
+from bzrlib import commands, errors, workingtree, ui
+
+
+class cmd_bench_patience(commands.Command):
+
+    takes_args = ['filename']
+
+    def run(self, filename):
+        tree, relpath = workingtree.WorkingTree.open_containing(filename)
+        tree.lock_read()
+        try:
+            file_id = tree.path2id(relpath)
+            w = tree.branch.repository.weave_store.get_weave(file_id,
+                transaction=tree.branch.repository.get_transaction())
+            self.outf.write('getting versions ... ')
+            self.outf.flush()
+            versions = w.versions()
+            self.outf.write('%d\n' % (len(versions,)))
+            self.outf.write('getting texts ... ')
+            self.outf.flush()
+            texts = w.get_line_list(versions)
+            total_len = sum(len(t) for t in texts)
+            self.outf.write('%d total bytes\n' % total_len)
+            last_text = ''
+            from bzrlib.patiencediff import PatienceSequenceMatcher
+            times = []
+            pb = ui.ui_factory.nested_progress_bar()
+            try:
+                t_overall_start = time.time()
+                for idx, text in enumerate(texts):
+                    pb.update('comparing', idx, len(texts))
+                    matcher = PatienceSequenceMatcher(None, last_text, text)
+                    last_text = text
+                    t_start = time.time()
+                    matcher.get_matching_blocks()
+                    t_delta = time.time() - t_start
+                    times.append(t_delta)
+                total_time = time.time() - t_overall_start
+            finally:
+                pb.finished()
+            avg = sum(times) / float(len(times))
+            max_time = max(times)
+            min_time = min(times)
+            print 'Total: %.3fs, min: %.3fs avg: %.3fs max: %.3fs' % (
+                total_time, min_time, avg, max_time)
+        finally:
+            tree.unlock()
+
+
+commands.register_command(cmd_bench_patience)



More information about the bazaar-commits mailing list