~bzr-pqm/bzr/bzr.dev

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

"""Tests for bzr working tree performance."""

import os

from bzrlib import ignores
from bzrlib.benchmarks import Benchmark
from bzrlib.workingtree import WorkingTree


class WorkingTreeBenchmark(Benchmark):
    """Benchmarks for `bzrlib.workingtree` performance."""

    def test_list_files_kernel_like_tree(self):
        tree = self.make_kernel_like_added_tree()
        tree.lock_read()
        try:
            self.time(list, tree.list_files())
        finally:
            tree.unlock()

    def test_list_files_unknown_kernel_like_tree(self):
        tree = self.make_kernel_like_tree(link_working=True)
        tree = WorkingTree.open('.')
        # Bzr only traverses directories if they are versioned
        # So add all the directories, but not the files, yielding
        # lots of unknown files.
        for root, dirs, files in os.walk('.'):
            if '.bzr' in dirs:
                dirs.remove('.bzr')
            if root == '.':
                continue
            tree.add(root)
        tree.lock_read()
        try:
            self.time(list, tree.list_files())
        finally:
            tree.unlock()

    def test_is_ignored_single_call(self):
        """How long does is_ignored take to initialise and check one file."""
        t = self.make_branch_and_tree('.')
        self.time(t.is_ignored, "CVS")

    def test_is_ignored_10824_calls(self):
        """How long does is_ignored take to initialise and check one file."""
        t = self.make_branch_and_tree('.')
        def call_is_ignored_10824_not_ignored():
            for x in xrange(10824):
                t.is_ignored(str(x))
        self.time(call_is_ignored_10824_not_ignored)

    def test_is_ignored_10_patterns(self):
        t = self.make_branch_and_tree('.')
        ignores.add_runtime_ignores([u'*.%i' % i for i in range(1, 9)])
        ignores.add_runtime_ignores(['./foo', 'foo/bar'])
        self.time(t.is_ignored,'bar')
        ignores._runtime_ignores = set()

    def test_is_ignored_50_patterns(self):
        t = self.make_branch_and_tree('.')
        ignores.add_runtime_ignores([u'*.%i' % i for i in range(1, 49)])
        ignores.add_runtime_ignores(['./foo', 'foo/bar'])
        self.time(t.is_ignored,'bar')
        ignores._runtime_ignores = set()

    def test_is_ignored_100_patterns(self):
        t = self.make_branch_and_tree('.')
        ignores.add_runtime_ignores([u'*.%i' % i for i in range(1, 99)])
        ignores.add_runtime_ignores(['./foo', 'foo/bar'])
        self.time(t.is_ignored,'bar')
        ignores._runtime_ignores = set()

    def test_is_ignored_1000_patterns(self):
        t = self.make_branch_and_tree('.')
        ignores.add_runtime_ignores([u'*.%i' % i for i in range(1, 999)])
        ignores.add_runtime_ignores(['./foo', 'foo/bar'])
        self.time(t.is_ignored,'bar')
        ignores._runtime_ignores = set()

    def test_walkdirs_kernel_like_tree(self):
        """Walking a kernel sized tree is fast!(150ms)."""
        self.make_kernel_like_tree()
        self.run_bzr('add')
        tree = WorkingTree.open('.')
        # on roberts machine: this originally took:  157ms/4177ms
        # plain os.walk takes 213ms on this tree
        self.time(list, tree.walkdirs())

    def test_walkdirs_kernel_like_tree_unknown(self):
        """Walking a kernel sized tree is fast!(150ms)."""
        self.make_kernel_like_tree()
        tree = WorkingTree.open('.')
        # on roberts machine: this originally took:  157ms/4177ms
        # plain os.walk takes 213ms on this tree
        self.time(list, tree.walkdirs())