~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/benchmarks/bench_cache_utf8.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 by Canonical Ltd
 
1
# Copyright (C) 2006 Canonical Ltd
2
2
#
3
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.
 
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.
6
7
#
7
8
# This program is distributed in the hope that it will be useful,
8
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
14
# along with this program; if not, write to the Free Software
14
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
15
16
 
 
17
 
16
18
"""Tests for encoding performance."""
17
19
 
18
20
from bzrlib import (
33
35
 
34
36
 
35
37
class EncodingBenchmark(Benchmark):
 
38
    """Benchmark the time to encode strings."""
36
39
 
37
40
    def setUp(self):
38
41
        super(EncodingBenchmark, self).setUp()
104
107
 
105
108
    def test_encode_1k_by_1k_unicode(self):
106
109
        """Test encoding 5 revisions 100k times"""
107
 
        revisions = ['\u062c\u0648\u062c\u0648' +
 
110
        revisions = [u'\u062c\u0648\u062c\u0648' +
108
111
                     unicode(osutils.rand_chars(60)) for x in xrange(1000)]
109
112
        self.time(self.encode_multi, revisions, 1000)
110
113
 
111
114
    def test_encode_1k_by_1k_unicode_cached(self):
112
115
        """Test encoding 5 revisions 100k times"""
113
 
        revisions = ['\u062c\u0648\u062c\u0648' +
 
116
        revisions = [u'\u062c\u0648\u062c\u0648' +
114
117
                     unicode(osutils.rand_chars(60)) for x in xrange(1000)]
115
118
        self.time(self.encode_cached_multi, revisions, 1000)
116
119
 
 
120
    def test_encode_500K_by_1_ascii(self):
 
121
        revisions = [unicode("test%07d" % x) for x in xrange(500000)]
 
122
        self.time(self.encode_multi, revisions, 1)
 
123
 
 
124
    def test_encode_500K_by_1_ascii_cached(self):
 
125
        revisions = [unicode("test%07d" % x) for x in xrange(500000)]
 
126
        self.time(self.encode_cached_multi, revisions, 1)
 
127
 
 
128
    def test_encode_500K_by_1_unicode(self):
 
129
        revisions = [u'\u062c\u0648\u062c\u0648' +
 
130
                     unicode("%07d" % x) for x in xrange(500000)]
 
131
        self.time(self.encode_multi, revisions, 1)
 
132
 
 
133
    def test_encode_500K_by_1_unicode_cached(self):
 
134
        revisions = [u'\u062c\u0648\u062c\u0648' +
 
135
                     unicode("%07d" % x) for x in xrange(500000)]
 
136
        self.time(self.encode_cached_multi, revisions, 1)
 
137
 
117
138
 
118
139
class DecodingBenchmarks(Benchmark):
 
140
    """Benchmark the time to decode strings."""
119
141
 
120
142
    def setUp(self):
121
143
        super(DecodingBenchmarks, self).setUp()
171
193
 
172
194
    def test_decode_1k_by_1k_unicode(self):
173
195
        """Test decoding 5 revisions 100k times"""
174
 
        revisions = [('\u062c\u0648\u062c\u0648' +
 
196
        revisions = [(u'\u062c\u0648\u062c\u0648' +
175
197
                      unicode(osutils.rand_chars(60))).encode('utf8')
176
198
                     for x in xrange(1000)]
177
199
        self.time(self.decode_multi, revisions, 1000)
178
200
 
179
201
    def test_decode_1k_by_1k_unicode_cached(self):
180
202
        """Test decoding 5 revisions 100k times"""
181
 
        revisions = [('\u062c\u0648\u062c\u0648' +
 
203
        revisions = [(u'\u062c\u0648\u062c\u0648' +
182
204
                      unicode(osutils.rand_chars(60))).encode('utf8')
183
205
                     for x in xrange(1000)]
184
206
        self.time(self.decode_cached_multi, revisions, 1000)
 
207
 
 
208
    def test_decode_500K_by_1_ascii(self):
 
209
        revisions = [("test%07d" % x) for x in xrange(500000)]
 
210
        self.time(self.decode_multi, revisions, 1)
 
211
 
 
212
    def test_decode_500K_by_1_ascii_cached(self):
 
213
        revisions = [("test%07d" % x) for x in xrange(500000)]
 
214
        self.time(self.decode_cached_multi, revisions, 1)
 
215
 
 
216
    def test_decode_500K_by_1_unicode(self):
 
217
        revisions = [(u'\u062c\u0648\u062c\u0648' +
 
218
                      unicode("%07d" % x)).encode('utf-8')
 
219
                     for x in xrange(500000)]
 
220
        self.time(self.decode_multi, revisions, 1)
 
221
 
 
222
    def test_decode_500K_by_1_unicode_cached(self):
 
223
        revisions = [(u'\u062c\u0648\u062c\u0648' +
 
224
                      unicode("%07d" % x)).encode('utf-8')
 
225
                     for x in xrange(500000)]
 
226
        self.time(self.decode_cached_multi, revisions, 1)