Newbie question: files..

Sonny Parlin sparlin at openpro.org
Sun Oct 10 12:13:21 EDT 1999


"Fredrik Lundh" <fredrik at pythonware.com> writes:

> age, different execution models, different
> approach to typing, etc, etc.
> 
> as for reading text files, it's a well-known
> fact that Perl is sometimes *faster* than C:
> 
>     http://www.deja.com/getdoc.xp?AN=505288860
> 

WOW, now that's interesting! I never would have guessed something like
that. Are you saying that perl code such as:

while(<FD>) {
  print "$_\n";
}

could be faster than low level C code such as:

while ((c = read (fd, buf, BUF_SIZE)) > 0)
	write (1, buf, c);

Not sure about that, or do you mean using C file pointers (i.e. stdio, as
opposed to lower level methods (i.e. unistd/fcntl which is what my C
example shows above))? I just tried those two pieces of code measuring time
with /bin/time and the C version was consistently faster than the perl
version... But I could see where using C file pointers and higher level
functions such as fgets would be slower than Perl, especially if Perl code
is implemented using the lower level methods underneath...

Please keep in mind that I'm pretty ignorant to how Perl (or python for
that matter) is implemented under the hood. And it sounds like you know a
bit more about that, so forgive me if I'm pushing the issue here, I'm just
trying to learn...

> unfortunately, Python's file object is still
> layered on top of C's stdio.  but that may
> of course change some day...
> 

As opposed to unistd or fcntl?

> for more info on other speed issues, skip
> over to http://www.python.org/search/
> and search for "is perl faster than python"
> (and similar phrases) in the newsgroup
> archives.
> 


Thanks for all your advice!

-Sonny
-- 
Sonny Parlin
sparlin at openpro.org
http://www.openpro.org
fingerprint = 45 FE 56 72 C2 04 CD 76  
		09 75 52 7A C6 7C 23 D2




More information about the Python-list mailing list