cPickle alternative?

Drochom pedrosch at gazeta.pl
Sat Aug 16 00:58:58 CEST 2003


> 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
>
Hello, and Thanks, your code was extremely helpful:)

Regards
Przemo Drochomirecki






More information about the Python-list mailing list