~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_dirstate.py

  • Committer: John Arbash Meinel
  • Date: 2007-05-07 19:12:44 UTC
  • mto: This revision was merged to the branch mainline in revision 2643.
  • Revision ID: john@arbash-meinel.com-20070507191244-ywyxg0ftlh6n297f
Add benchmarks to see how reading the dirstate changes when you have parents.
Currently, the C implementation is slower than python, but partially that is
because it is not optimized (at all).

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
 
32
32
 
33
33
class BenchmarkDirState(benchmarks.Benchmark):
 
34
    """Benchmarks for DirState functions."""
34
35
 
35
36
    def build_helper(self, layout):
36
37
        """This is a helper with the common build_??_dirstate funcs.
87
88
        """
88
89
        return self.build_helper([(10, 0), (10, 0), (10, 20)])
89
90
 
90
 
    def test_build_20k_dirblocks(self):
 
91
    def build_20k_dirstate_with_parents(self, num_parents):
 
92
        """Build a DirState file with 20k records and N parents.
 
93
 
 
94
        With 1 parent, this is equivalent to after a simple commit. With 2 it
 
95
        is equivalent to after a merge.
 
96
        """
 
97
        # All files are marked as changed in the same revision, and this occurs
 
98
        # supposedly in the history of the current trees.
 
99
        last_changed_id = generate_ids.gen_revision_id('joe@foo.com')
 
100
        parent_revision_ids = [generate_ids.gen_revision_id('joe@foo.com')
 
101
                               for i in xrange(num_parents)]
 
102
        # Start with a dirstate file with 0 parents
 
103
        state = self.build_20k_dirstate()
 
104
        state.lock_write()
 
105
        try:
 
106
            # This invasively updates the internals of DirState to be fast,
 
107
            # since we don't have an api other than passing in Revision Tree
 
108
            # objects, but that requires having a real inventory, etc.
 
109
            for entry in state._iter_entries():
 
110
                minikind, fingerprint, size, is_exec, packed_stat = entry[1][0]
 
111
                for parent_id in parent_revision_ids:
 
112
                    # Add a parent record for this record
 
113
                    entry[1].append((minikind, fingerprint, size, is_exec,
 
114
                                     last_changed_id))
 
115
            state._parents = parent_revision_ids
 
116
            state._ghosts = []
 
117
            state._dirblock_state = dirstate.DirState.IN_MEMORY_MODIFIED
 
118
            state._header_state = dirstate.DirState.IN_MEMORY_MODIFIED
 
119
            state._validate()
 
120
            state.save()
 
121
        finally:
 
122
            state.unlock()
 
123
        return state
 
124
 
 
125
    def test_build_20k_dirstate(self):
91
126
        state = self.time(self.build_20k_dirstate)
92
127
        state.lock_read()
93
128
        try:
96
131
        finally:
97
132
            state.unlock()
98
133
 
99
 
    def test__py_read_dirblocks_20k_tree_no_parents(self):
100
 
        state = self.build_20k_dirstate()
101
 
        state.lock_read()
102
 
        try:
103
 
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
104
 
                             state._dirblock_state)
105
 
            state._read_header_if_needed()
106
 
            self.time(dirstate._py_read_dirblocks, state)
107
 
        finally:
108
 
            state.unlock()
109
 
 
110
 
    def test__c_read_dirblocks_20k_tree_no_parents(self):
111
 
        self.requireFeature(CompiledDirstateHelpersFeature)
112
 
        from bzrlib.compiled.dirstate_helpers import _c_read_dirblocks
113
 
        state = self.build_20k_dirstate()
 
134
    def test_build_20k_dirstate_1_parent(self):
 
135
        state = self.time(self.build_20k_dirstate_with_parents, 1)
 
136
        state.lock_read()
 
137
        try:
 
138
            state._validate()
 
139
            entries = list(state._iter_entries())
 
140
            self.assertEqual(21111, len(entries))
 
141
        finally:
 
142
            state.unlock()
 
143
 
 
144
    def test_build_20k_dirstate_2_parents(self):
 
145
        state = self.time(self.build_20k_dirstate_with_parents, 2)
 
146
        state.lock_read()
 
147
        try:
 
148
            state._validate()
 
149
            entries = list(state._iter_entries())
 
150
            self.assertEqual(21111, len(entries))
 
151
        finally:
 
152
            state.unlock()
 
153
 
 
154
    def test__py_read_dirblocks_20k_tree_0_parents(self):
 
155
        state = self.build_20k_dirstate()
 
156
        state.lock_read()
 
157
        try:
 
158
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
 
159
                             state._dirblock_state)
 
160
            state._read_header_if_needed()
 
161
            self.time(dirstate._py_read_dirblocks, state)
 
162
        finally:
 
163
            state.unlock()
 
164
 
 
165
    def test__c_read_dirblocks_20k_tree_0_parents(self):
 
166
        self.requireFeature(CompiledDirstateHelpersFeature)
 
167
        from bzrlib.compiled.dirstate_helpers import _c_read_dirblocks
 
168
        state = self.build_20k_dirstate()
 
169
        state.lock_read()
 
170
        try:
 
171
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
 
172
                             state._dirblock_state)
 
173
            state._read_header_if_needed()
 
174
            self.time(_c_read_dirblocks, state)
 
175
        finally:
 
176
            state.unlock()
 
177
 
 
178
    def test__py_read_dirblocks_20k_tree_1_parent(self):
 
179
        state = self.build_20k_dirstate_with_parents(1)
 
180
        state.lock_read()
 
181
        try:
 
182
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
 
183
                             state._dirblock_state)
 
184
            state._read_header_if_needed()
 
185
            self.time(dirstate._py_read_dirblocks, state)
 
186
        finally:
 
187
            state.unlock()
 
188
 
 
189
    def test__c_read_dirblocks_20k_tree_1_parent(self):
 
190
        self.requireFeature(CompiledDirstateHelpersFeature)
 
191
        from bzrlib.compiled.dirstate_helpers import _c_read_dirblocks
 
192
        state = self.build_20k_dirstate_with_parents(1)
 
193
        state.lock_read()
 
194
        try:
 
195
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
 
196
                             state._dirblock_state)
 
197
            state._read_header_if_needed()
 
198
            self.time(_c_read_dirblocks, state)
 
199
        finally:
 
200
            state.unlock()
 
201
 
 
202
    def test__py_read_dirblocks_20k_tree_2_parents(self):
 
203
        state = self.build_20k_dirstate_with_parents(2)
 
204
        state.lock_read()
 
205
        try:
 
206
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,
 
207
                             state._dirblock_state)
 
208
            state._read_header_if_needed()
 
209
            self.time(dirstate._py_read_dirblocks, state)
 
210
        finally:
 
211
            state.unlock()
 
212
 
 
213
    def test__c_read_dirblocks_20k_tree_2_parents(self):
 
214
        self.requireFeature(CompiledDirstateHelpersFeature)
 
215
        from bzrlib.compiled.dirstate_helpers import _c_read_dirblocks
 
216
        state = self.build_20k_dirstate_with_parents(2)
114
217
        state.lock_read()
115
218
        try:
116
219
            self.assertEqual(dirstate.DirState.NOT_IN_MEMORY,