.readline() - VERY SLOW compared to PERL

Erno Kuusela erno-news at erno.iki.fi
Thu Nov 16 13:49:12 EST 2000


>>>>> "Fluffy" == Swapped Out Fluffy <ftc at meowing.net> writes:

    Fluffy> The standard readline() is relatively slow because it uses
    Fluffy> a very conservative, safe, portable approach.  It reads
    Fluffy> the file one character at a time, meaning that your C
    Fluffy> library and/or kernel has lots of work to do.

no wonder it is slow!

a couple of speedup possibilities come to mind:

 * use getc_unlocked & friends if available, so that there's no need
   to lock the file object on each call. (susv2 requires the regular
   versions to do locking,
   <URL:http://www.opennc.org/onlinepubs/7908799/xsh/getc_unlocked.html>)

 * use the getline function on gnu platforms.
   <URL:http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/
   library_11.html#SEC124>

this would add a few #ifdefs, but the performance increase could
be worth it.


  -- erno




More information about the Python-list mailing list