Convert String to Dictionary question

MDK mdk at mdk.com
Fri Feb 15 08:40:34 EST 2002


"Jason Orendorff" <jason at jorendorff.com> wrote in message
news:mailman.1013729004.19316.python-list at python.org...
> MDK wrote:
> > Pickling seems too slow.
>
> Really?  What makes you say this?
>
> In some random tests on my box, it seems that
> repr() is a teensy bit faster than cPickle.dumps(), and
> eval() is several times slower than cPickle.loads().
>
> ## Jason Orendorff    http://www.jorendorff.com/
>

Here is a copy/paste from the documentation (see note at end):

#-----------------------------------------------------------------

3.14 pickle -- Python object serialization

The pickle module implements a basic but powerful algorithm for ``pickling''
(a.k.a. serializing, marshalling or flattening) nearly arbitrary Python
objects. This is the act of converting objects to a stream of bytes (and
back: ``unpickling''). This is a more primitive notion than persistence --
although pickle reads and writes file objects, it does not handle the issue
of naming persistent objects, nor the (even more complicated) area of
concurrent access to persistent objects. The pickle module can transform a
complex object into a byte stream and it can transform the byte stream into
an object with the same internal structure. The most obvious thing to do
with these byte streams is to write them onto a file, but it is also
conceivable to send them across a network or store them in a database. The
module shelve provides a simple interface to pickle and unpickle objects on
DBM-style database files.

Note: The pickle module is rather slow. A reimplementation of the same
algorithm in C, which is up to 1000 times faster, is available as the
cPickle module. This has the same interface except that Pickler and
Unpickler are factory functions, not classes (so they cannot be used as base
classes for inheritance).

#-----------------------------------------------------------------

My concern was that even though cPickle is supposed to be faster is does not
mean that is it as fast as it needs to be.





More information about the Python-list mailing list