in reply to Re: Re: read data 1 byte at a time
in thread read data 1 byte at a time
I ran your benchmark and got a few warnings about "Parentheses missing around "my" list at (eval 42) line 3.", which I tracked down to the my $char in sysread test.Strange, I cannot reproduce that. If I check man perldiag, it says:
but there's no assignment going on here. Note that the sysopen and open lines use the same construct (using our instead of my), and there it doesn't warn. Which version of Perl are you using?Parentheses missing around "%s" list (W parenthesis) You said something like my $foo, $bar = @_; when you meant my ($foo, $bar) = @_; Remember that "my", "our", and "local" bind tighter than comma.
For variety, if the file is less than a couple of hundred megs, slurping the whole thing and using substr to iterate the chars is a fair bit quicker.Welllllll, your benchmark isn't fair. All others do two things in the loop, assign a character to $char, and increment an integer. If I change the 'substr' test to:
I get the following results:substr => 'seek $fh4 => 0, SEEK_SET or die; my ($char, $data); sysread $fh4 => $data, -s $file; $c4 = 0; $char = substr $data => $c4 ++, 1 for 0 .. length ($d +ata) - 1'
Of course, the differences between substr and readline are minimal, and even getc is in the same ballpark.Rate sysread getc substr readline sysread 6.48/s -- -54% -60% -63% getc 14.0/s 117% -- -14% -19% substr 16.3/s 152% 16% -- -6% readline 17.4/s 169% 24% 7% -- 72192 : 72192 : 72192 : 72192
Abigail
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: read data 1 byte at a time
by BrowserUk (Patriarch) on Oct 28, 2003 at 22:30 UTC | |
by Abigail-II (Bishop) on Oct 28, 2003 at 22:42 UTC |