Speed of Python vs. Perl

Tim Peters tim.one at home.com
Fri Jan 12 03:10:05 EST 2001


[Tim]
> Unless you've got a broken installation, Python shouldn't be
> spending *any* time parsing imported files at startup.

[Fredrik Lundh]
> well, isn't "unmarshalling" a form of parsing?
>
> (read token, figure out what it means, update data structure, repeat
> until end of data)

Sure.  Then so is executing bytecode (read bytecode, figure out what it
means, update data structures, repeat until RETURN).  You *know* how Guido
feels about hypergeneralization <wink>.

> note that unmarshal uses lots of getc calls, and we all know what
> that means for performance...  how about changing read_compiled_module()
> from
>
>     co = PyMarshal_ReadObjectFromFile(fp);
>
> to something like:
>
>     size = getsize(fp)
>     if size could be determined, and is less than 200k:
>         buf = malloc(size)
>         fread(buf, 1, size, fp)
>         co = PyMarshal_ReadObjectFromString(buf, size)
>         free(buf)
>     else:
>         co = PyMarshal_ReadObjectFromFile(fp);

Talk someone into writing a patch; I've got no bandwidth to spare.

and-neither-do-you-or-you-would-have-already-written-it<wink>-ly
    y'rs  - tim





More information about the Python-list mailing list