1
# Copyright (C) 2007 Canonical Ltd
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Benchmarks for Knit performance"""
26
from bzrlib.benchmarks import Benchmark
27
from bzrlib.tests.test_knit import CompiledKnitFeature
30
class BenchKnitIndex(Benchmark):
31
"""Benchmark Knit index performance."""
33
def create_50k_index(self):
34
"""Create an knit index file with 50,000 entries.
36
This isn't super realistic, but it *is* big :)
38
The file 'test.kndx' will be created.
40
rev_id = generate_ids.gen_revision_id('long.name@this.example.com')
41
versions = [(rev_id, ('fulltext',), 0, 200, [])]
44
for i in xrange(49999):
45
if alt_parent is not None:
46
parent_ids = [rev_id, alt_parent]
50
# The *next* entry will be a merge
54
rev_id = generate_ids.gen_revision_id('long.name@this.example.com')
55
versions.append((rev_id, ('line-delta',), pos, 200, parent_ids))
57
t = self.get_transport()
58
kndx = knit._KnitIndex(t, 'test.kndx', 'w', create=True,
60
kndx.add_versions(versions)
62
def setup_load_data_c(self):
63
self.requireFeature(CompiledKnitFeature)
64
orig = knit._load_data
66
knit._load_data = orig
67
self.addCleanup(reset)
68
from bzrlib._knit_load_data_c import _load_data_c
69
knit._load_data = _load_data_c
71
def setup_load_data_py(self):
72
orig = knit._load_data
74
knit._load_data = orig
75
self.addCleanup(reset)
76
from bzrlib._knit_load_data_py import _load_data_py
77
knit._load_data = _load_data_py
79
def test_read_50k_index_c(self):
80
self.setup_load_data_c()
81
self.create_50k_index()
82
t = self.get_transport()
83
kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
85
def test_read_50k_index_c_again(self):
86
self.setup_load_data_c()
87
self.create_50k_index()
88
t = self.get_transport()
89
kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
91
def test_read_50k_index_py(self):
92
self.create_50k_index()
93
self.setup_load_data_py()
94
t = self.get_transport()
95
kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')
97
def test_read_50k_index_py_again(self):
98
self.create_50k_index()
99
self.setup_load_data_py()
100
t = self.get_transport()
101
kndx = self.time(knit._KnitIndex, t, 'test.kndx', 'r')