~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_log.py

  • Committer: John Arbash Meinel
  • Date: 2007-04-09 22:11:22 UTC
  • mto: This revision was merged to the branch mainline in revision 2566.
  • Revision ID: john@arbash-meinel.com-20070409221122-qh66j4pk3kqxjn9c
Cleanup bzrlib/benchmarks/* so that everything at least has a valid doc string.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
from bzrlib.transform import TreeTransform
27
27
from bzrlib.workingtree import WorkingTree
28
28
 
 
29
 
29
30
class LinesDone(Exception):
 
31
    """Raised when `LineConsumer` reaches the required number of lines."""
30
32
    pass
31
33
 
 
34
 
32
35
class LineConsumer(object):
 
36
    """Count lines that are produced.
 
37
 
 
38
    When the required number of lines have been reached, raise `LinesDone`.
 
39
    """
33
40
 
34
41
    def __init__(self, required_lines):
 
42
        """Create a new consumer.
 
43
 
 
44
        :param required_lines: How many lines must be produced.
 
45
        :type required_lines: integer
 
46
        """
35
47
        self.required_lines = required_lines
36
48
 
37
49
    def write(self, text):
 
50
        """Write some text to the black hole.
 
51
 
 
52
        But count how many lines have been written.
 
53
 
 
54
        :param text: A string that would be written.
 
55
        :raise LinesDone: when the required number of lines has been reached.
 
56
        :return: None
 
57
        """
38
58
        self.required_lines -= text.count('\n')
39
59
        if self.required_lines < 0:
40
60
            raise LinesDone()
41
 
        
 
61
 
42
62
 
43
63
class LogBenchmark(Benchmark):
 
64
    """Benchmarks for ``'bzr log'`` performance."""
44
65
 
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')