1
# Copyright (C) 2006 Canonical Ltd
1
# Copyright (C) 2006 by 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 as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
4
# it under the terms of the GNU General Public License version 2 as published by
5
# the Free Software Foundation.
8
7
# This program is distributed in the hope that it will be useful,
9
8
# but WITHOUT ANY WARRANTY; without even the implied warranty of
13
12
# You should have received a copy of the GNU General Public License
14
13
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
14
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
16
"""Tests for encoding performance."""
108
105
def test_encode_1k_by_1k_unicode(self):
109
106
"""Test encoding 5 revisions 100k times"""
110
revisions = [u'\u062c\u0648\u062c\u0648' +
107
revisions = ['\u062c\u0648\u062c\u0648' +
111
108
unicode(osutils.rand_chars(60)) for x in xrange(1000)]
112
109
self.time(self.encode_multi, revisions, 1000)
114
111
def test_encode_1k_by_1k_unicode_cached(self):
115
112
"""Test encoding 5 revisions 100k times"""
116
revisions = [u'\u062c\u0648\u062c\u0648' +
113
revisions = ['\u062c\u0648\u062c\u0648' +
117
114
unicode(osutils.rand_chars(60)) for x in xrange(1000)]
118
115
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)
139
118
class DecodingBenchmarks(Benchmark):
140
"""Benchmark the time to decode strings."""
143
121
super(DecodingBenchmarks, self).setUp()
194
172
def test_decode_1k_by_1k_unicode(self):
195
173
"""Test decoding 5 revisions 100k times"""
196
revisions = [(u'\u062c\u0648\u062c\u0648' +
174
revisions = [('\u062c\u0648\u062c\u0648' +
197
175
unicode(osutils.rand_chars(60))).encode('utf8')
198
176
for x in xrange(1000)]
199
177
self.time(self.decode_multi, revisions, 1000)
201
179
def test_decode_1k_by_1k_unicode_cached(self):
202
180
"""Test decoding 5 revisions 100k times"""
203
revisions = [(u'\u062c\u0648\u062c\u0648' +
181
revisions = [('\u062c\u0648\u062c\u0648' +
204
182
unicode(osutils.rand_chars(60))).encode('utf8')
205
183
for x in xrange(1000)]
206
184
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)