[MERGE] rand_chars() optimization
Dmitry Vasiliev
dima at hlabs.spb.ru
Sun Mar 11 13:39:43 GMT 2007
Marius Gedminas wrote:
> On Sun, Mar 11, 2007 at 03:43:59PM +0300, Dmitry Vasiliev wrote:
>> +
>> +class RandCharsBenchmark(Benchmark):
>> +
>> + def test_rand_chars(self):
>> + def generate_rand_chars():
>> + items = set(osutils.rand_chars(50) for i in xrange(200000))
>
> Why do you include the creation of a large set of strings in the
> benchmark?
Good catch, actually it just was a copy/paste from the corresponding
test. I'll change it into less memory-aggressive code like this:
for i in xrange(200000):
item = osutils.rand_chars(50)
>> ALNUM = '0123456789abcdefghijklmnopqrstuvwxyz'
>> +_rand_chars_map = dict((chr(i), ALNUM[i % 36]) for i in range(256))
>
> I suspect it might be a bit faster if you used a string rather than a
> dict here:
>
> _rand_chars_map = ALNUM * (255 / len(ALNUM) + 1)
But how it may helps to make rand_chars() any faster? With
_rand_chars_map as a dict you just can do later _rand_chars_map[raw_byte].
--
Dmitry Vasiliev <dima at hlabs.spb.ru>
http://hlabs.spb.ru
More information about the bazaar
mailing list