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:
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.
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?
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:
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'
I get the following results:
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
Of course, the differences between substr and readline are minimal, and even getc is in the same ballpark.

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
    Which version of Perl are you using?

    v5.8.0 / AS 802. Not sure why the warning is produced. By the evidence of the pod you quoted, it's a bug, but I never encountered it before.

    Welllllll, your benchmark isn't fair. All others do two things in the loop, assign a character to $char, and increment an integer.

    True! ... but I already knew how many chars there were, so I didn't need to count 'em:)


    Examine what is said, not who speaks.
    "Efficiency is intelligent laziness." -David Dunham
    "Think for yourself!" - Abigail
    Hooray!

      I see it with 5.8.0 as well. But not with 5.8.1, 5.8.2-RC1, or 5.9.0. So, I guess it's a bug that's fixed in the current release.

      Abigail