cPickle alternative?

Drochom pedrosch at gazeta.pl
Fri Aug 15 18:33:51 EDT 2003


"Michael Peuser" <mpeuser at web.de> wrote in message
news:bhj56t$1d8$03$1 at news.t-online.com...
> o.k - I modified my testprogram - let it run at your machine.
> It took 1.5 seconds - I made it 11 Million records to get  to 2 Mbyte.
> Kindly
> Michael
> ------------------
> import cPickle as Pickle
> from time import clock
>
> # generate 1.000.000 records
> r=[(('k', 5, 0),), (('*', 0, 0),), (('t', 1, 1),), (('o', 2, 0),), (('t',
3,
> 0),), (('a', 4, 0), ('o', 2, 0))]
>
> x=[]
>
> for i in xrange(1000000):
>     x.append(r)
>
> print len(x), "records"
>
> t0=clock()
> f=open ("test","w")
> Pickle.dump(x,f,1)
> f.close()
> print "out=", clock()-t0
>
> t0=clock()
> f=open ("test")
> x=Pickle.load(f)
> f.close()
> print "in=", clock()-t0
> ---------------------

Hi, i'm really grateful for your help,
i've modyfied your code a bit, check your times and tell me what are they

TRY THIS:

import cPickle as Pickle
from time import clock
from random import randrange


x=[]

for i in xrange(20000):
 c = []
 for j in xrange(randrange(2,25)):
  c.append((chr(randrange(33,120)),randrange(1,100000),randrange(1,3)))
 c = tuple(c)
 x.append(c)
 if i%1000==0: print i #it will help you to survive waiting...
print len(x), "records"

t0=clock()
f=open ("test","w")
Pickle.dump(x,f,0)
f.close()
print "out=", clock()-t0


t0=clock()
f=open ("test")
x=Pickle.load(f)
f.close()
print "in=", clock()-t0

Thanks once again:)







More information about the Python-list mailing list