[Python-3000] characters data type

Josiah Carlson jcarlson at uci.edu
Fri May 5 00:35:30 CEST 2006


"Guido van Rossum" <guido at python.org> wrote:
> Can you please post the benchmarking code?

No problem.


 - Josiah


import time
import array

block = 1025*'\0'
block2 = array.array("B", 1024*[0])
desired_size = 16*1024*1024

incrs = []
for mns in (1024, 0):
    y = []
    x = 1024
    while x < desired_size:
        y.append(max((x>>3) + 7, mns))
        x += y[-1]
    _ = y.pop() #we'll be generous and not do the final one.
    incrs.append(y)

for k in (1024, 135, 64):
    t = time.clock()
    for i in xrange(100):
        l = []
        for j in xrange(0, desired_size, k):
            l.append(block[:k])
        l = ''.join(l)
        del l
    
    print k, time.clock()-t

z = time.clock()
for i in xrange(100):
    x = array.array("B", block2)
    del x

z = time.clock()-z

for increments in incrs:
    t = time.clock()
    for i in xrange(100):
        x = array.array("B", block2)
        for j in increments:
            x.extend(x[:j])
        del x
    print increments[0], time.clock()-t-z




More information about the Python-3000 mailing list