1
# Copyright (C) 2006 by Canonical Ltd
1
# Copyright (C) 2006 Canonical Ltd
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.
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
16
18
"""Tests for encoding performance."""
18
20
from bzrlib import (
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)
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)
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)
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)
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)
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)
118
139
class DecodingBenchmarks(Benchmark):
140
"""Benchmark the time to decode strings."""
121
143
super(DecodingBenchmarks, self).setUp()
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)
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)
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)
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)
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)
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)