cPickle alternative?

Scott David Daniels Scott.Daniels at Acm.Org
Fri Aug 15 19:52:44 CEST 2003


Drochom wrote:
> Thanks for help:)
> Here is simple example:
> frankly speaking it's a graph with 100000 nodes:
> STRUCTURE:
> [(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t', 3,
> 0),), (('a', 4, 0), ('o', 2, 0))]

Perhaps this matches your spec:

from random import randrange
import pickle, cPickle, time

source = [(chr(randrange(33, 127)), randrange(100000), randrange(i+50))
           for i in range(100000)]


def timed(module, flag, name='file.tmp'):
     start = time.time()
     dest = file(name, 'wb')
     module.dump(source, dest, flag)
     dest.close()
     mid = time.time()
     dest = file(name, 'rb')
     result = module.load(dest)
     dest.close()
     stop = time.time()
     assert source == result
     return mid-start, stop-mid

On 2.2:
timed(pickle, 0): (7.8, 5.5)
timed(pickle, 1): (9.5, 6.2)
timed(cPickle, 0): (0.41, 4.9)
timed(cPickle, 1): (0.15, .53)

On 2.3:
timed(pickle, 0): (6.2, 5.3)
timed(pickle, 1): (6.6, 5.4)
timed(pickle, 2): (6.5, 3.9)

timed(cPickle, 0): (6.2, 5.3)
timed(pickle, 1): (.88, .69)
timed(pickle, 2): (.80, .67)

(Not tightly controlled -- I'd gues 1.5 digits)

-Scott David Daniels
Scott.Daniels at Acm.Org





More information about the Python-list mailing list