Buffered/Unbuffered on HP-UX (was: Yet another Python vs. Perl speed issue/quest

nanotech at europa.com nanotech at europa.com
Wed Mar 14 11:06:17 EST 2001


Paul/Christian/All:

Thanks for all your help! With some offline help from Paul, it looks 
like the problem is either with HP-UX or how Python was compiled for 
HP-UX. Running the correct code (you are definitely right Christian, 
I posted "bad" Python code!), buffered/unbuffered on Linux is just as 
fast as the Perl (which *is* correct Christian; I am using Perl 
5.004, what is yours?).

Thanks for listening and the group's existance,

  Quentin Crain

--- In python-list at y..., tanzer at s... (Christian Tanzer) wrote:
> 
> nanotech at e... wrote:
> 
> > Python 2.0 on an HP (nice and big) takes ~30 seconds to lowercase 
all
> > the lines in a 3meg file. Perl takes less than a second. What am I
> > doing wrong?!?
> >
> > Python
> > ------
> > import sys
> > import string
> >
> > stdin=sys.stdin
> > lower=string.lower
> >
> > print map(lower,stdin.readlines())
> >
> > Perl
> > ----
> >
> > print map(lc,<STDIN>);
> 
> Your Python code is doing unnecessary work (BTW, it doesn't do what
> you expect). Just for comparison, the timings for a 3MB file on my
> aging Pentium Pro 200 MHz machine:
> 
>     $ time python /tmp/test1.py < /tmp/test.txt > /tmp/test.out 
>     real    0m10.246s
>     user    0m4.810s
>     sys     0m1.190s
>     $ time python /tmp/test2.py < /tmp/test.txt > /tmp/test.out 
>     real    0m0.781s
>     user    0m0.200s
>     sys     0m0.270s
> 
>     #### test1.py                       #### test2.py
>     import sys                          import sys
>     import string                       import string
>     stdin=sys.stdin                     stdin=sys.stdin
>     lower=string.lower                  lower=string.lower
>     print map(lower,stdin.readlines())  sys.stdout.write(lower
(stdin.read()))
> 
> Your perl code gives a compilation error:
> 
>     $ time perl /tmp/test1.pl < /tmp/test.txt > /tmp/test.out
>     Not enough arguments for lower case at /tmp/test1.pl line 1, 
near "lc,"
>     Execution of /tmp/test1.pl aborted due to compilation errors.
> 
> Slightly changed, it lies halfway between the two python versions:
> 
>     $ time perl /tmp/test2.pl < /tmp/test.txt > /tmp/test.out
>     real    0m3.297s
>     user    0m2.830s
>     sys     0m0.360s
> 
>     #### test2.pl
>     print map {lc ($_)} <STDIN>;
> 
> -- 
> Christian Tanzer                                         tanzer at s...
> Glasauergasse 32                                       Tel: +43 1 
876 62 36
> A-1130 Vienna, Austria                                 Fax: +43 1 
877 66 92
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list






More information about the Python-list mailing list