13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
17
"""Tests for tree transform performance"""
26
26
from bzrlib.transform import TreeTransform
27
27
from bzrlib.workingtree import WorkingTree
29
30
class LinesDone(Exception):
31
"""Raised when `LineConsumer` reaches the required number of lines."""
32
35
class LineConsumer(object):
36
"""Count lines that are produced.
38
When the required number of lines have been reached, raise `LinesDone`.
34
41
def __init__(self, required_lines):
42
"""Create a new consumer.
44
:param required_lines: How many lines must be produced.
45
:type required_lines: integer
35
47
self.required_lines = required_lines
37
49
def write(self, text):
50
"""Write some text to the black hole.
52
But count how many lines have been written.
54
:param text: A string that would be written.
55
:raise LinesDone: when the required number of lines has been reached.
38
58
self.required_lines -= text.count('\n')
39
59
if self.required_lines < 0:
43
63
class LogBenchmark(Benchmark):
64
"""Benchmarks for ``'bzr log'`` performance."""
45
66
def test_log(self):
46
"""Run log in a many-commit tree."""
67
"""Run log in a many-commit tree."""
47
68
tree = self.make_many_commit_tree(hardlink=True)
48
69
lf = log_formatter('long', to_file=StringIO())
49
70
self.time(show_log, tree.branch, lf, direction='reverse')
80
101
self.time(log_screenful)
82
103
def test_cmd_log(self):
83
"""Test execution of the log command."""
104
"""Test execution of the log command."""
84
105
tree = self.make_many_commit_tree(hardlink=True)
85
self.time(self.run_bzr, 'log', '-r', '-4..')
106
self.time(self.run_bzr, ['log', '-r', '-4..'])
87
108
def test_cmd_log_subprocess(self):
88
"""Text startup and execution of the log command."""
109
"""Text startup and execution of the log command."""
89
110
tree = self.make_many_commit_tree(hardlink=True)
90
111
self.time(self.run_bzr_subprocess, 'log', '-r', '-4..')