/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_cache_utf8.py

  • Committer: v.ladeuil+lp at free
  • Date: 2006-10-12 14:29:32 UTC
  • mto: (2145.1.1 keepalive)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: v.ladeuil+lp@free.fr-20061012142932-7221fe16d2b48fa3
Shuffle http related test code. Hopefully it ends up at the right place :)

* bzrlib/tests/HttpServer.py: 
New file. bzrlib.tests.ChrootedTestCase use HttpServer. So the
class can't be defined in bzrlib.tests.HTTPUtils because it
creates a circular dependency (bzrlib.tests.HTTPUtils needs to
import bzrlib.tests).

* bzrlib/transport/http/_urllib.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/_pycurl.py: 
Transfer test server definition to bzrlib.tests.HttpServer. Clean
up imports.

* bzrlib/transport/http/__init__.py: 
Transfer all test related code to either bzrlib.tests.HttpServer
and bzrlib.tests.HTTPUtils.
Fix all use of TransportNotPossible and InvalidURL by prefixing it
by 'errors.' (this seems to be the preferred way in the rest of
bzr).
Get rid of unused imports.

* bzrlib/tests/test_transport.py:
(ReadonlyDecoratorTransportTest.test_local_parameters,
FakeNFSDecoratorTests.test_http_parameters): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_sftp_transport.py:
(set_test_transport_to_sftp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

* bzrlib/tests/test_selftest.py:
(TestTestCaseWithTransport.test_get_readonly_url_http): Use
HttpServer from bzrlib.tests.HttpServer instead of
bzrlib.transport.http.

* bzrlib/tests/test_repository.py: 
Does *not* use HttpServer.

* bzrlib/tests/test_http.py: 
Build on top of bzrlib.tests.HttpServer and bzrlib.tests.HTTPUtils
instead of bzrlib.transport.http.

* bzrlib/tests/test_bzrdir.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_http.py:
(HTTPBranchTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/branch_implementations/test_branch.py:
(ChrootedTests.setUp): Use HttpServer from bzrlib.tests.HttpServer
instead of bzrlib.transport.http.

* bzrlib/tests/__init__.py:
(ChrootedTestCase.setUp): Use HttpServer from
bzrlib.tests.HttpServer instead of bzrlib.transport.http.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Canonical Ltd
 
2
#
 
3
# This program is free software; you can redistribute it and/or modify
 
4
# it under the terms of the GNU General Public License version 2 as published by
 
5
# the Free Software Foundation.
 
6
#
 
7
# This program is distributed in the hope that it will be useful,
 
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
# GNU General Public License for more details.
 
11
#
 
12
# You should have received a copy of the GNU General Public License
 
13
# along with this program; if not, write to the Free Software
 
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
 
 
16
"""Tests for encoding performance."""
 
17
 
 
18
from bzrlib import (
 
19
    cache_utf8,
 
20
    osutils,
 
21
    )
 
22
 
 
23
from bzrlib.benchmarks import Benchmark
 
24
 
 
25
 
 
26
_normal_revision_id = (u'john@arbash-meinel.com-20060801200018'
 
27
                       u'-cafa6272d9b8cac4')
 
28
_unicode_revision_id = (u'\u062c\u0648\u062c\u0648@\xe5rbash-meinel.com-'
 
29
                        u'\xb5\xb5\xb5-20060801200018-cafa6272d9b8cac4')
 
30
 
 
31
_normal_revision_id_utf8 = _normal_revision_id.encode('utf-8')
 
32
_unicode_revision_id_utf8 = _unicode_revision_id.encode('utf-8')
 
33
 
 
34
 
 
35
class EncodingBenchmark(Benchmark):
 
36
 
 
37
    def setUp(self):
 
38
        super(EncodingBenchmark, self).setUp()
 
39
        # Make sure we start and end with a clean cache
 
40
        cache_utf8.clear_encoding_cache()
 
41
        self.addCleanup(cache_utf8.clear_encoding_cache)
 
42
 
 
43
    def encode_1M(self, revision_id):
 
44
        """Encode the given revision id 1 million times"""
 
45
        # In a real kernel tree there are 7.7M lines of code
 
46
        # so the initial import actually has to encode a revision
 
47
        # id to store annotated lines one time for every line.
 
48
        for i in xrange(1000000):
 
49
            revision_id.encode('utf8')
 
50
 
 
51
    def encode_cached_1M(self, revision_id):
 
52
        """Encode the given revision id 1 million times using the cache"""
 
53
        encode = cache_utf8.encode
 
54
        for i in xrange(1000000):
 
55
            encode(revision_id)
 
56
 
 
57
    def encode_multi(self, revision_list, count):
 
58
        """Encode each entry in the list count times"""
 
59
        for i in xrange(count):
 
60
            for revision_id in revision_list:
 
61
                revision_id.encode('utf-8')
 
62
 
 
63
    def encode_cached_multi(self, revision_list, count):
 
64
        """Encode each entry in the list count times"""
 
65
        encode = cache_utf8.encode
 
66
        for i in xrange(count):
 
67
            for revision_id in revision_list:
 
68
                encode(revision_id)
 
69
 
 
70
    def test_encode_1_by_1M_ascii(self):
 
71
        """Test encoding a single revision id 1 million times."""
 
72
        self.time(self.encode_1M, _normal_revision_id)
 
73
 
 
74
    def test_encode_1_by_1M_ascii_cached(self):
 
75
        """Test encoding a single revision id 1 million times."""
 
76
        self.time(self.encode_cached_1M, _normal_revision_id)
 
77
 
 
78
    def test_encode_1_by_1M_ascii_str(self):
 
79
        # We have places that think they have a unicode revision id
 
80
        # but actually, they have a plain string. So .encode(utf8)
 
81
        # actually has to decode from ascii, and then encode into utf8
 
82
        self.time(self.encode_1M, str(_normal_revision_id))
 
83
 
 
84
    def test_encode_1_by_1M_ascii_str_cached(self):
 
85
        self.time(self.encode_cached_1M, str(_normal_revision_id))
 
86
 
 
87
    def test_encode_1_by_1M_unicode(self):
 
88
        """Test encoding a single revision id 1 million times."""
 
89
        self.time(self.encode_1M, _unicode_revision_id)
 
90
 
 
91
    def test_encode_1_by_1M_unicode_cached(self):
 
92
        """Test encoding a single revision id 1 million times."""
 
93
        self.time(self.encode_cached_1M, _unicode_revision_id)
 
94
 
 
95
    def test_encode_1k_by_1k_ascii(self):
 
96
        """Test encoding 5 revisions 100k times"""
 
97
        revisions = [unicode(osutils.rand_chars(60)) for x in xrange(1000)]
 
98
        self.time(self.encode_multi, revisions, 1000)
 
99
 
 
100
    def test_encode_1k_by_1k_ascii_cached(self):
 
101
        """Test encoding 5 revisions 100k times"""
 
102
        revisions = [unicode(osutils.rand_chars(60)) for x in xrange(1000)]
 
103
        self.time(self.encode_cached_multi, revisions, 1000)
 
104
 
 
105
    def test_encode_1k_by_1k_unicode(self):
 
106
        """Test encoding 5 revisions 100k times"""
 
107
        revisions = ['\u062c\u0648\u062c\u0648' +
 
108
                     unicode(osutils.rand_chars(60)) for x in xrange(1000)]
 
109
        self.time(self.encode_multi, revisions, 1000)
 
110
 
 
111
    def test_encode_1k_by_1k_unicode_cached(self):
 
112
        """Test encoding 5 revisions 100k times"""
 
113
        revisions = ['\u062c\u0648\u062c\u0648' +
 
114
                     unicode(osutils.rand_chars(60)) for x in xrange(1000)]
 
115
        self.time(self.encode_cached_multi, revisions, 1000)
 
116
 
 
117
 
 
118
class DecodingBenchmarks(Benchmark):
 
119
 
 
120
    def setUp(self):
 
121
        super(DecodingBenchmarks, self).setUp()
 
122
        # Make sure we start and end with a clean cache
 
123
        cache_utf8.clear_encoding_cache()
 
124
        self.addCleanup(cache_utf8.clear_encoding_cache)
 
125
 
 
126
    def decode_1M(self, revision_id):
 
127
        for i in xrange(1000000):
 
128
            revision_id.decode('utf8')
 
129
 
 
130
    def decode_cached_1M(self, revision_id):
 
131
        decode = cache_utf8.decode
 
132
        for i in xrange(1000000):
 
133
            decode(revision_id)
 
134
 
 
135
    def decode_multi(self, revision_list, count):
 
136
        for i in xrange(count):
 
137
            for revision_id in revision_list:
 
138
                revision_id.decode('utf-8')
 
139
 
 
140
    def decode_cached_multi(self, revision_list, count):
 
141
        decode = cache_utf8.decode
 
142
        for i in xrange(count):
 
143
            for revision_id in revision_list:
 
144
                decode(revision_id)
 
145
 
 
146
    def test_decode_1_by_1M_ascii(self):
 
147
        """Test decoding a single revision id 1 million times."""
 
148
        self.time(self.decode_1M, _normal_revision_id_utf8)
 
149
 
 
150
    def test_decode_1_by_1M_ascii_cached(self):
 
151
        """Test decoding a single revision id 1 million times."""
 
152
        self.time(self.decode_cached_1M, _normal_revision_id_utf8)
 
153
 
 
154
    def test_decode_1_by_1M_unicode(self):
 
155
        """Test decoding a single revision id 1 million times."""
 
156
        self.time(self.decode_1M, _unicode_revision_id_utf8)
 
157
 
 
158
    def test_decode_1_by_1M_unicode_cached(self):
 
159
        """Test decoding a single revision id 1 million times."""
 
160
        self.time(self.decode_cached_1M, _unicode_revision_id_utf8)
 
161
 
 
162
    def test_decode_1k_by_1k_ascii(self):
 
163
        """Test decoding 5 revisions 100k times"""
 
164
        revisions = [osutils.rand_chars(60) for x in xrange(1000)]
 
165
        self.time(self.decode_multi, revisions, 1000)
 
166
 
 
167
    def test_decode_1k_by_1k_ascii_cached(self):
 
168
        """Test decoding 5 revisions 100k times"""
 
169
        revisions = [osutils.rand_chars(60) for x in xrange(1000)]
 
170
        self.time(self.decode_cached_multi, revisions, 1000)
 
171
 
 
172
    def test_decode_1k_by_1k_unicode(self):
 
173
        """Test decoding 5 revisions 100k times"""
 
174
        revisions = [('\u062c\u0648\u062c\u0648' +
 
175
                      unicode(osutils.rand_chars(60))).encode('utf8')
 
176
                     for x in xrange(1000)]
 
177
        self.time(self.decode_multi, revisions, 1000)
 
178
 
 
179
    def test_decode_1k_by_1k_unicode_cached(self):
 
180
        """Test decoding 5 revisions 100k times"""
 
181
        revisions = [('\u062c\u0648\u062c\u0648' +
 
182
                      unicode(osutils.rand_chars(60))).encode('utf8')
 
183
                     for x in xrange(1000)]
 
184
        self.time(self.decode_cached_multi, revisions, 1000)