~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
# Copyright (C) 2006 by Canonical Ltd
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as published by
# the Free Software Foundation.
#
# 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

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

import os

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


class WorkingTreeBenchmark(Benchmark):

    def test_list_files_kernel_like_tree(self):
        self.make_kernel_like_tree()
        self.run_bzr('add')
        tree = WorkingTree.open('.')
        self.time(list, tree.list_files())

    def test_list_files_unknown_kernel_like_tree(self):
        self.make_kernel_like_tree()
        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)
        self.time(list, tree.list_files())

    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)