[tahoe-dev] Base32

Jeremy R. Fishman jfishman at bowdoin.edu
Sat Mar 7 10:15:40 PST 2009


Hi all,

Is there a particular reason Tahoe uses its own implementation of 
base32.encode()?  I personally agree with the use of lowercase, but 
would this be better accomplished via base64.b32encode(...).lower()


cProfile on 10000 160-bit binary strings :

 >>> def test(n, chrs):
...   pop = ''.join(map(chr, range(256))) * chrs
...   r = random.Random()
...   l = []
...   for i in xrange(n):
...     s = ''.join(r.sample(pop, chrs))
...     a = base32.encode(s)
...     b = base64.b32encode(s).lower()
...     if a != b:
...        raise ArithmeticError('encodings do not match')
...     l.append(a)
...   return l
...
 >>> cProfile.run('results = test(10000, 20)')
         1820399 function calls in 10.473 CPU seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
   [...]
   320000    2.077    0.000    3.395    0.000 base32.py:21(_encode)
    10000    2.199    0.000    5.949    0.001 base32.py:4(encode)
    10000    0.786    0.000    1.358    0.000 base64.py:135(b32encode)
   [...]
    10000    0.035    0.000    0.035    0.000 {method 'lower' of 'str' 
objects}
   [...]



Maybe speed isn't that important, but seems to me like we should be 
using the library function anyway (>=Python2.4, is that an issue?).

  - Jeremy


More information about the tahoe-dev mailing list